|
Revision 1787, 2.0 kB
(checked in by Andrew Dolgov <fox@bah.spb.su>, 1 year ago)
|
[project @ add dummy plug for mb_strtolower]
|
| Line | |
|---|
| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
if (!function_exists('mb_strlen')) |
|---|
| 4 |
{ |
|---|
| 5 |
|
|---|
| 6 |
// author Martin Kutschker <martin.t.kutschker@blackbox.net> |
|---|
| 7 |
function mb_strlen($str, $encoding="utf-8") |
|---|
| 8 |
{ |
|---|
| 9 |
if($encoding != "utf-8") |
|---|
| 10 |
{ return -1; } |
|---|
| 11 |
|
|---|
| 12 |
$n=0; |
|---|
| 13 |
|
|---|
| 14 |
for($i=0; isset($str{$i}); $i++) |
|---|
| 15 |
{ |
|---|
| 16 |
$c = ord($str{$i}); |
|---|
| 17 |
|
|---|
| 18 |
if (!($c & 0x80)) |
|---|
| 19 |
$n++; |
|---|
| 20 |
|
|---|
| 21 |
elseif (($c & 0xC0) == 0xC0) |
|---|
| 22 |
$n++; |
|---|
| 23 |
} |
|---|
| 24 |
|
|---|
| 25 |
return $n; |
|---|
| 26 |
} |
|---|
| 27 |
} |
|---|
| 28 |
|
|---|
| 29 |
if (!function_exists('mb_substr')) |
|---|
| 30 |
{ |
|---|
| 31 |
|
|---|
| 32 |
// author Martin Kutschker <martin.t.kutschker@blackbox.net> |
|---|
| 33 |
function mb_substr($str, $start, $len=null, $encoding="utf-8") |
|---|
| 34 |
{ |
|---|
| 35 |
if($encoding != "utf-8") |
|---|
| 36 |
{ return -1; } |
|---|
| 37 |
|
|---|
| 38 |
$byte_start = utf8_char2byte_pos($str,$start); |
|---|
| 39 |
|
|---|
| 40 |
if ($byte_start === false) |
|---|
| 41 |
return false; |
|---|
| 42 |
|
|---|
| 43 |
$str = substr($str,$byte_start); |
|---|
| 44 |
|
|---|
| 45 |
if ($len != null) |
|---|
| 46 |
{ |
|---|
| 47 |
$byte_end = utf8_char2byte_pos($str,$len); |
|---|
| 48 |
|
|---|
| 49 |
if ($byte_end === false) |
|---|
| 50 |
return $str; |
|---|
| 51 |
else |
|---|
| 52 |
return substr($str,0,$byte_end); |
|---|
| 53 |
} |
|---|
| 54 |
|
|---|
| 55 |
else return $str; |
|---|
| 56 |
} |
|---|
| 57 |
|
|---|
| 58 |
function utf8_char2byte_pos($str,$pos) |
|---|
| 59 |
{ |
|---|
| 60 |
$n = 0; |
|---|
| 61 |
$p = abs($pos); |
|---|
| 62 |
|
|---|
| 63 |
if ($pos >= 0) |
|---|
| 64 |
{ |
|---|
| 65 |
$i = 0; |
|---|
| 66 |
$d = 1; |
|---|
| 67 |
} else { |
|---|
| 68 |
$i = strlen($str)-1; |
|---|
| 69 |
$d = -1; |
|---|
| 70 |
} |
|---|
| 71 |
|
|---|
| 72 |
for( ; isset($str{$i}) && $n<$p; $i+=$d) |
|---|
| 73 |
{ |
|---|
| 74 |
$c = (int)ord($str{$i}); |
|---|
| 75 |
|
|---|
| 76 |
if (!($c & 0x80)) |
|---|
| 77 |
$n++; |
|---|
| 78 |
elseif (($c & 0xC0) == 0xC0) |
|---|
| 79 |
$n++; |
|---|
| 80 |
} |
|---|
| 81 |
|
|---|
| 82 |
if (!isset($str{$i})) |
|---|
| 83 |
return false; |
|---|
| 84 |
|
|---|
| 85 |
if ($pos >= 0) |
|---|
| 86 |
{ |
|---|
| 87 |
|
|---|
| 88 |
while ((ord($str{$i}) & 0x80) && !(ord($str{$i}) & 0x40)) |
|---|
| 89 |
{ $i++; } |
|---|
| 90 |
} else { |
|---|
| 91 |
|
|---|
| 92 |
$i++; |
|---|
| 93 |
} |
|---|
| 94 |
|
|---|
| 95 |
return $i; |
|---|
| 96 |
} |
|---|
| 97 |
|
|---|
| 98 |
if (!function_exists('mb_strtolower')) { |
|---|
| 99 |
function mb_strtolower($msg, $encoding) { |
|---|
| 100 |
return $msg; |
|---|
| 101 |
} |
|---|
| 102 |
} |
|---|
| 103 |
} |
|---|
| 104 |
|
|---|