note 56298 added to function.convert-cyr-string
| From: | webmaster at chassidus dot ru | Date: | Tue, 30 Aug 2005 05:51:47 +0000 |
| Subject: | note 56298 added to function.convert-cyr-string | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-94364@lists.php.net to get a copy of this message | ||
//I've also built the same way for hebrew to utf converting
function heb2utf($s) {
for($i=0, $m=strlen($s); $i<$m; $i++) {
$c=ord($s[$i]);
if ($c<=127) {$t.=chr($c); continue; }
if ($c>=224 ) {$t.=chr(215).chr($c-80); continue; }
}
return $t;
}
//Simple unicoder and decoder for hebrew and russian:
function unicode_hebrew($str) {
for ($ii=0;$ii<strlen($str);$ii++) {
$xchr=substr($str,$ii,1);
if (ord($xchr)>223) {
$xchr=ord($xchr)+1264;
$xchr="&#" . $xchr . ";";
}
$encode=$encode . $xchr;
}
return $encode;
}
function unicode_russian($str) {
for ($ii=0;$ii<strlen($str);$ii++) {
$xchr=substr($str,$ii,1);
if (ord($xchr)>191) {
$xchr=ord($xchr)+848;
$xchr="&#" . $xchr . ";";
}
$encode=$encode . $xchr;
}
return $encode;
}
function decode_unicoded_hebrew($str) {
$decode="";
$ar=split("&#",$str);
foreach ($ar as $value ) {
$in1=strpos($value,";"); //end of code
if ($in1>0) {// unicode
$code=substr($value,0,$in1);
if ($code>=1456 and $code<=1514) { //hebrew
$code=$code-1264;
$xchr=chr($code);
} else { //other unicode
$xchr="&#" . $code . ";";
}
$xchr=$xchr . substr($value,$in1+1);
} else //not unicode
$xchr = $value;
$decode=$decode . $xchr;
}
return $decode;
}
function decode_unicoded_russian($str) {
$decode="";
$ar=split("&#",$str);
foreach ($ar as $value ) {
$in1=strpos($value,";"); //end of code
if ($in1>0) {// unicode
$code=substr($value,0,$in1);
if ($code>=1040 and $code<=1103) {
$code=$code-848;
$xchr=chr($code);
} else {
$xchr="&#" . $code . ";";
}
$xchr=$xchr . substr($value,$in1+1);
} else
$xchr = $value;
$decode=$decode . $xchr;
}
return $decode;
}
----
Manual Page -- http://www.php.net/manual/en/function.convert-cyr-string.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+56298
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56298&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56298&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56298&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56298&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56298&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56298&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+56298&report=yes
Search -- http://master.php.net/manage/user-notes.php