note 73422 added to function.unicode-encode

From: Date: Thu, 22 Feb 2007 16:45:18 +0000
Subject: note 73422 added to function.unicode-encode
Groups: php.notes 
Request: Send a blank email to php-notes+get-123717@lists.php.net to get a copy of this message
A PHP4 Version for converting a utf8 string/text to unicode: function utf8_to_unicode( $str ) { $unicode = array(); $values = array(); $lookingFor = 1; for ($i = 0; $i < strlen( $str ); $i++ ) { $thisValue = ord( $str[ $i ] ); if ( $thisValue < ord('A') ) { // exclude 0-9 if ($thisValue >= ord('0') && $thisValue <= ord('9')) { // number $unicode[] = chr($thisValue); } else { $unicode[] = '%'.dechex($thisValue); } } else { if ( $thisValue < 128) $unicode[] = $str[ $i ]; else { if ( count( $values ) == 0 ) $lookingFor = ( $thisValue < 224 ) ? 2 : 3; $values[] = $thisValue; if ( count( $values ) == $lookingFor ) { $number = ( $lookingFor == 3 ) ? ( ( $values[0] % 16 ) * 4096 ) + ( ( $values[1] % 64 ) * 64 ) + ( $values[2] % 64 ): ( ( $values[0] % 32 ) * 64 ) + ( $values[1] % 64 ); $number = dechex($number); $unicode[] = (strlen($number)==3)?"%u0".$number:"%u".$number; $values = array(); $lookingFor = 1; } // if } // if } } // for return implode("",$unicode); } // utf8_to_unicode ---- Server IP: 217.13.201.10 Probable Submitter: 195.227.103.146 ---- Manual Page -- http://www.php.net/manual/en/function.unicode-encode.php Edit -- https://master.php.net/note/edit/73422 Del: integrated -- https://master.php.net/note/delete/73422/integrated Del: useless -- https://master.php.net/note/delete/73422/useless Del: bad code -- https://master.php.net/note/delete/73422/bad+code Del: spam -- https://master.php.net/note/delete/73422/spam Del: non-english -- https://master.php.net/note/delete/73422/non-english Del: in docs -- https://master.php.net/note/delete/73422/in+docs Del: other reasons-- https://master.php.net/note/delete/73422 Reject -- https://master.php.net/note/reject/73422 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#123717) next »