note 58461 added to function.utf8-encode

From: Date: Fri, 04 Nov 2005 22:34:00 +0000
Subject: note 58461 added to function.utf8-encode
Groups: php.notes 
Request: Send a blank email to php-notes+get-98092@lists.php.net to get a copy of this message
// Reads a file story.txt ascii (as typed on keyboard) // converts it to Georgian character using utf8 encoding // if I am correct(?) just as it should be when typed on Georgian computer // it outputs it as an html file // // http://www.comweb.nl/keys_to_georgian.html // http://www.comweb.nl/keys_to_georgian.php // http://www.comweb.nl/story.txt <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML> <HEAD> <TITLE>keys to unicode code</TITLE> // this meta tag is needed <meta http-equiv="Content-Type" content="text/html;charset=utf-8" > // note the sylfean font seems to be standard installed on Windows XP // It supports Georgian <style TYPE="text/css"> <!-- body {font-family:sylfaen; } --> </style> </HEAD> <BODY> <? $eng=array(97,98,99,100,101,102,103,104,105,106,107,108,109,110,111, 112,113,114,115,116,117,118,119,120,121,122,87,82,84,83, 67,74,90); $geo=array(4304,4305,4330,4307,4308,4324,4306,4336,4312,4335,4313, 4314,4315,4316,4317,4318,4325,4320,4321,4322,4323,4309, 4332,4334,4327,4310,4333,4326,4311,4328,4329,4319,4331, 91,93,59,39,44,46,96); $fc=file("story.txt"); foreach($fc as $line) { $spacestart=1; for ($i=0; $i<strlen($line); $i+=1) { $character=ord(substr($line,$i,1)); $found=0; for ($k=0; $k<count($eng); $k+=1) { if ($eng[$k]==$character) { print code2utf( $geo[$k] ); $found=1; } } if ($found==0) { if ($character==126 || $character==32 || $character==10 || $character==9) { if ($character==9) { print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'; } if ($character==10) { print "<BR>\n"; } if ($character==32) { if ($spacestart==1) {print '&nbsp;'; } else { print " "; } } if ($character==126){ print "~"; } } else { print substr($line,$i,1); } } if ($character!=32) { $spacestart=0; } } } /** * Function coverts number of utf char into that character. * Function taken from: http://sk2.php.net/manual/en/function.utf8-encode.php#49336 * * @param int $num * @return utf8char */ function code2utf($num) { if($num<128)return chr($num); if($num<2048)return chr(($num>>6)+192).chr(($num&63)+128); if($num<65536)return chr(($num>>12)+224).chr((($num>>6)&63)+128).chr(($num&63)+128); if($num<2097152)return chr(($num>>18)+240).chr((($num>>12)&63)+128).chr((($num>>6)&63)+128) .chr(($num&63)+128); return ''; } ?> </BODY> </HTML> ---- Manual Page -- http://www.php.net/manual/en/function.utf8-encode.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+58461 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+58461&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+58461&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+58461&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+58461&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+58461&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+58461&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+58461&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+58461&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#98092) next »