note 98240 added to function.ord

From: Date: Thu, 03 Jun 2010 15:14:01 +0000
Subject: note 98240 added to function.ord
Groups: php.notes 
Request: Send a blank email to php-notes+get-169858@lists.php.net to get a copy of this message
For anyone having trouble trying to detect the encoding of a string because PHP provides no easy way to see the characters (and byte values) of a string, here's a function that returns the characters and byte values for the ASCII and UTF-8 encodings: <?php function hex_chars($data) { $mb_chars = ''; $mb_hex = ''; for ($i=0; $i<mb_strlen($data, 'UTF-8'); $i++) { $c = mb_substr($data, $i, 1, 'UTF-8'); $mb_chars .= '{'. ($c). '}'; $o = unpack('N', mb_convert_encoding($c, 'UCS-4BE', 'UTF-8')); $mb_hex .= '{'. hex_format($o[1]). '}'; } $chars = ''; $hex = ''; for ($i=0; $i<strlen($data); $i++) { $c = substr($data, $i, 1); $chars .= '{'. ($c). '}'; $hex .= '{'. hex_format(ord($c)). '}'; } return array( 'data' => $data, 'chars' => $chars, 'hex' => $hex, 'mb_chars' => $mb_chars, 'mb_hex' => $mb_hex, ); } function hex_format($o) { $h = strtoupper(dechex($o)); $len = strlen($h); if ($len % 2 == 1) $h = "0$h"; return $h; } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 86.121.33.154 ---- Manual Page -- http://www.php.net/manual/en/function.ord.php Edit -- https://master.php.net/note/edit/98240 Del: integrated -- https://master.php.net/note/delete/98240/integrated Del: useless -- https://master.php.net/note/delete/98240/useless Del: bad code -- https://master.php.net/note/delete/98240/bad+code Del: spam -- https://master.php.net/note/delete/98240/spam Del: non-english -- https://master.php.net/note/delete/98240/non-english Del: in docs -- https://master.php.net/note/delete/98240/in+docs Del: other reasons-- https://master.php.net/note/delete/98240 Reject -- https://master.php.net/note/reject/98240 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#169858) next »