note 76916 added to function.ord

From: Date: Sun, 05 Aug 2007 07:40:15 +0000
Subject: note 76916 added to function.ord
Groups: php.notes 
Request: Send a blank email to php-notes+get-129189@lists.php.net to get a copy of this message
An update for ng4rrjanbiah's uniord() in #46267. Again, no mbstring requirement - this is just a code cleanup. Longer, but prettier - I think, anyway ;) function uniord($ch) { $n = ord($ch{0}); if ($n < 128) { return $n; // no conversion required } if ($n < 192 || $n > 253) { return false; // bad first byte || out of range } $arr = array(1 => 192, // byte position => range from 2 => 224, 3 => 240, 4 => 248, 5 => 252, ); foreach ($arr as $key => $val) { if ($n >= $val) { // add byte to the 'char' array $char[] = ord($ch{$key}) - 128; $range = $val; } else { break; // save some e-trees } } $retval = ($n - $range) * pow(64, sizeof($char)); foreach ($char as $key => $val) { $pow = sizeof($char) - ($key + 1); // invert key $retval += $val * pow(64, $pow); // dark magic } return $retval; } ---- Server IP: 194.145.210.4 Probable Submitter: 62.31.252.73 ---- Manual Page -- http://www.php.net/manual/en/function.ord.php Edit -- https://master.php.net/note/edit/76916 Del: integrated -- https://master.php.net/note/delete/76916/integrated Del: useless -- https://master.php.net/note/delete/76916/useless Del: bad code -- https://master.php.net/note/delete/76916/bad+code Del: spam -- https://master.php.net/note/delete/76916/spam Del: non-english -- https://master.php.net/note/delete/76916/non-english Del: in docs -- https://master.php.net/note/delete/76916/in+docs Del: other reasons-- https://master.php.net/note/delete/76916 Reject -- https://master.php.net/note/reject/76916 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#129189) next »