note 46267 added to function.ord

From: Date: Tue, 05 Oct 2004 08:01:58 +0000
Subject: note 46267 added to function.ord
Groups: php.notes 
Request: Send a blank email to php-notes+get-78011@lists.php.net to get a copy of this message
[Fixed a bug in my previous note; ord() is missing in first condition] uniord() function like "v0rbiz at yahoo dot com" (Note# 42778), but without using mbstring extension. Note: If the passed character is not valid, it may throw "Uninitialized string offset" notice (may set the error reporting to 0). <?php /** * @Algorithm: http://www1.tip.nl/~t876506/utf8tbl.html * @Logic: UTF-8 to Unicode conversion **/ function uniord($c) { $ud = 0; if (ord($c{0})>=0 && ord($c{0})<=127) $ud = ord($c{0}); if (ord($c{0})>=192 && ord($c{0})<=223) $ud = (ord($c{0})-192)*64 + (ord($c{1})-128); if (ord($c{0})>=224 && ord($c{0})<=239) $ud = (ord($c{0})-224)*4096 + (ord($c{1})-128)*64 + (ord($c{2})-128); if (ord($c{0})>=240 && ord($c{0})<=247) $ud = (ord($c{0})-240)*262144 + (ord($c{1})-128)*4096 + (ord($c{2})-128)*64 + (ord($c{3})-128); if (ord($c{0})>=248 && ord($c{0})<=251) $ud = (ord($c{0})-248)*16777216 + (ord($c{1})-128)*262144 + (ord($c{2})-128)*4096 + (ord($c{3})-128)*64 + (ord($c{4})-128); if (ord($c{0})>=252 && ord($c{0})<=253) $ud = (ord($c{0})-252)*1073741824 + (ord($c{1})-128)*16777216 + (ord($c{2})-128)*262144 + (ord($c{3})-128)*4096 + (ord($c{4})-128)*64 + (ord($c{5})-128); if (ord($c{0})>=254 && ord($c{0})<=255) //error $ud = false; return $ud; } //debug echo uniord('A'); //65 echo uniord("\xe0\xae\xb4"); //2996 ?> HTH, R. Rajesh Jeba Anbiah ---- Manual Page -- http://www.php.net/manual/en/function.ord.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+46267 Delete -- http://master.php.net/manage/user-notes.php?action=delete+46267&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+46267&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#78011) next »