note 68211 added to function.utf8-encode

From: Date: Tue, 18 Jul 2006 14:33:13 +0000
Subject: note 68211 added to function.utf8-encode
Groups: php.notes 
Request: Send a blank email to php-notes+get-114887@lists.php.net to get a copy of this message
I had some difficulty finding a way to easily write UTF-8 files with the byte order mark included. This is the simple solution I have come up with: <?php function writeUTF8File($filename,$content) { $dhandle=fopen($filename,"w"); # Now UTF-8 - Add byte order mark fwrite($dhandle, pack("CCC",0xef,0xbb,0xbf)); fwrite($dhandle,$content); fclose($dhandle); } ?> When you read the file back in using fopen, the BOM will also be there. To remove it, I also wrote the following function: <?php function removeBOM($str=""){ if(substr($str, 0,3) == pack("CCC",0xef,0xbb,0xbf)) { $str=substr($str, 3); } return $str; } ?> ---- Server IP: 85.116.0.130 Probable Submitter: 81.86.22.27 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.utf8-encode.php Edit -- http://master.php.net/note/edit/68211 Del: integrated -- http://master.php.net/note/delete/68211/integrated Del: useless -- http://master.php.net/note/delete/68211/useless Del: bad code -- http://master.php.net/note/delete/68211/bad+code Del: spam -- http://master.php.net/note/delete/68211/spam Del: non-english -- http://master.php.net/note/delete/68211/non-english Del: in docs -- http://master.php.net/note/delete/68211/in+docs Del: other reasons-- http://master.php.net/note/delete/68211 Reject -- http://master.php.net/note/reject/68211 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#114887) next »