note 55715 added to function.ord

From: Date: Thu, 11 Aug 2005 12:17:18 +0000
Subject: note 55715 added to function.ord
Groups: php.notes 
Request: Send a blank email to php-notes+get-93437@lists.php.net to get a copy of this message
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 ---- Manual Page -- http://www.php.net/manual/en/function.ord.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+55715 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55715&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55715&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55715&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55715&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55715&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55715&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+55715&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#93437) next »