note 68211 deleted from function.utf8-encode by cmb

From: Date: Sun, 22 Dec 2019 08:58:55 +0000
Subject: note 68211 deleted from function.utf8-encode by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-213571@lists.php.net to get a copy of this message
Note Submitter: James Cundle ---- 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; } ?>

« previous php.notes (#213571) next »