note 55715 deleted from function.ord by danbrown
| From: | danbrown@php.net | Date: | Tue, 11 Oct 2011 16:11:47 +0000 |
| Subject: | note 55715 deleted from function.ord by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-183804@lists.php.net to get a copy of this message | ||
Note Submitter: Nguyen Van Nhu
----
A function to convert a unicode-string to ascii-string of the Vietnamese langague, according to The
VIQR Convention (http://www.vietstd.org/). If you have the same kind of convention just create the
arrays. Contents of my arrays were to large to post here.
//ascii-sign-characters
$mapsigns2 =Array("sign");
//ascii-sign-characters
$mapsigns1 =Array("sign");
//ascii-letters-characters
$mapascii =Array("letters");
//unicode characters
$mapunicode = Array("unicode");
function uniword2ascii($str)
{
global $mapsigns1, $mapsigns2,$mapunicode, $mapascii;
$length = strlen($str);
$ReturnStr = "";
for ($i=0; $i<$length; $i++)
{
$uniord = 0;
if (ord($str{$i})>=0 && ord($str{$i})<=127)
$uniord = ord($str{$i});
elseif (ord($str{$i})>=192 && ord($str{$i})<=223)
{
$uniord = (ord($str{$i})-192)*64 + (ord($str{$i+1})-128);
$i = $i+1;
}
elseif (ord($str{$i})>=224 && ord($str{$i})<=239)
{
$uniord = (ord($str{$i})-224)*4096 + (ord($str{$i+1})-128)*64 + (ord($str{$i+2})-128);
$i = $i+2;
}
elseif (ord($str{$i})>=240 && ord($str{$i})<=247)
{
$uniord = (ord($str{$i})-240)*262144 + (ord($str{$i+1})-128)*4096 + (ord($str{$i+2})-128)*64 +
(ord($str{$i+3})-128);
$i = $i+3;
}
elseif (ord($str{$i})>=248 && ord($str{$i})<=251)
{
$uniord = (ord($str{$i})-248)*16777216 + (ord($str{$i+1})-128)*262144 +
(ord($str{$i+2})-128)*4096 + (ord($str{$i+3})-128)*64 + (ord($str{$i+4})-128);
$i = $i+4;
}
elseif (ord($str{$i})>=252 && ord($str{$i})<=253)
{
$uniord = (ord($str{$i})-252)*1073741824 + (ord($str{$i+1})-128)*16777216 +
(ord($str{$i+2})-128)*262144 + (ord($str{$i+3})-128)*4096 + (ord($str{$i+4})-128)*64 +
(ord($str{$i+5})-128);
$i = $i+5;
}
elseif (ord($str{$i})>=254 && ord($str{$i})<=255) //error
$uniord = 0;
//This part is for converting the string to a VIQR-string;
if ($uniord > 127 )
{
$key = array_search($uniord,$mapunicode);
if ($key)
{
$ReturnStr .= chr($mapascii[$key]) . chr($mapsigns1[$key]) . chr($mapsigns2[$key]);
}
else
{
$ReturnStr .= chr($uniord);
}
}
else
{
$ReturnStr .= chr($uniord);
}
//endOFfor
}
return $ReturnStr;
}
Best regards/Nguyen Van Nhu