break;
case 'iconv':
- $conv_str = iconv($str,$fromCS,$toCS.'//TRANSLIT');
+ $conv_str = iconv($fromCS,$toCS.'//TRANSLIT',$str);
if (false !== $conv_str) return $conv_str;
break;
case 'recode':
- $conv_str = recode_string($toCS.'..'.$fromCS,$str);
+ $conv_str = recode_string($fromCS.'..'.$toCS,$str);
if (false !== $conv_str) return $conv_str;
break;
}
if ($i === false) { // $len outside actual string length
return $string;
} else {
+ if ($len > 0) {
+ if (isset($string{$i})) {
+ return substr($string,0,$i).$crop;
+ }
+ } else {
+ if (isset($string{$i-1})) {
+ return $crop.substr($string,$i);
+ }
+ }
+
+/*
if (abs($len)<$this->strlen($charset,$string)) { // Has to use ->strlen() - otherwise multibyte strings ending with a multibyte char will return true here (which is not a catastrophe, but...)
if ($len > 0) {
return substr($string,0,$i).$crop;
return $crop.substr($string,$i);
}
}
+*/
}
return $string;
}
/**
* Translates all characters of a string into their respective case values.
* Unlike strtolower() and strtoupper() this method is locale independent.
+ * Note that the string length may change!
+ * eg. lower case German "ß" (scharfes S) becomes uper case "SS"
* Unit-tested by Kasper
* Real case folding is language dependent, this method ignores this fact.
*
$out = '';
$caseConv =& $this->caseFolding[$charset][$case];
- for($i=0; strlen($string{$i}); $i++) {
+ for($i=0; isset($string{$i}); $i++) {
$c = $string{$i};
$cc = $caseConv[$c];
if ($cc) {
*/
function utf8_strlen($str) {
$n=0;
- for($i=0; strlen($str{$i}); $i++) {
+ for($i=0; isset($str{$i}); $i++) {
$c = ord($str{$i});
if (!($c & 0x80)) // single-byte (0xxxxxx)
$n++;
$d = -1;
}
- for( ; strlen($str{$i}) && $n<$p; $i+=$d) {
+ for( ; isset($str{$i}) && $n<$p; $i+=$d) {
$c = (int)ord($str{$i});
if (!($c & 0x80)) // single-byte (0xxxxxx)
$n++;
elseif (($c & 0xC0) == 0xC0) // multi-byte starting byte (11xxxxxx)
$n++;
}
- if (!strlen($str{$i})) return false; // offset beyond string length
+ if (!isset($str{$i})) return false; // offset beyond string length
if ($pos >= 0) {
// skip trailing multi-byte data bytes
elseif (($c & 0xC0) == 0xC0) // multi-byte starting byte (11xxxxxx)
$n++;
}
- if (!strlen($str{$i})) return false; // offset beyond string length
+ if (!isset($str{$i})) return false; // offset beyond string length
return $n;
}
$out = '';
$caseConv =& $this->caseFolding['utf-8'][$case];
- for($i=0; strlen($str{$i}); $i++) {
+ for($i=0; isset($str{$i}); $i++) {
$c = ord($str{$i});
if (!($c & 0x80)) // single-byte (0xxxxxx)
$mbc = $str{$i};
*/
function euc_strtrunc($str,$len,$charset) {
$sjis = ($charset == 'shift_jis');
- for ($i=0; strlen($str{$i}) && $i<$len; $i++) {
+ for ($i=0; isset($str{$i}) && $i<$len; $i++) {
$c = ord($str{$i});
if ($sjis) {
if (($c >= 0x80 && $c < 0xA0) || ($c >= 0xE0)) $i++; // advance a double-byte char
if ($c >= 0x80) $i++; // advance a double-byte char
}
}
- if (!strlen($str{$i})) return $str; // string shorter than supplied length
+ if (!isset($str{$i})) return $str; // string shorter than supplied length
if ($i>$len)
return substr($str,0,$len-1); // we ended on a first byte
function euc_strlen($str,$charset) {
$sjis = ($charset == 'shift_jis');
$n=0;
- for ($i=0; strlen($str{$i}); $i++) {
+ for ($i=0; isset($str{$i}); $i++) {
$c = ord($str{$i});
if ($sjis) {
if (($c >= 0x80 && $c < 0xA0) || ($c >= 0xE0)) $i++; // advance a double-byte char
$d = -1;
}
- for ( ; strlen($str{$i}) && $n<$p; $i+=$d) {
+ for ( ; isset($str{$i}) && $n<$p; $i+=$d) {
$c = ord($str{$i});
if ($sjis) {
if (($c >= 0x80 && $c < 0xA0) || ($c >= 0xE0)) $i+=$d; // advance a double-byte char
$n++;
}
- if (!strlen($str{$i})) return false; // offset beyond string length
+ if (!isset($str{$i})) return false; // offset beyond string length
if ($pos < 0) $i++; // correct offset