note 46874 deleted from function.file-get-contents by aidan

From: Date: Mon, 31 Jan 2005 07:21:18 +0000
Subject: note 46874 deleted from function.file-get-contents by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-84258@lists.php.net to get a copy of this message
Note Submitter: Ned Baldessin ---- If you're opening text files encoded in UTF-8, you might get several (3 in my case) control characters at the start of the string. The reason is that file_get_contents() is binary safe, so you get every byte of the given file, and that very often, when saving text as UTF-8, text editors (I'm looking at you BBedit) save it by default with a "BOM" (Byte Order Mark). These characters are non-printable, so you can't see them if you echo() them. To check what's really going on, you can use this: <?php $str = file_get_contents('my_utf-8_file.txt'); echo $str{0}.' => '.ord($str{0})."\n"; echo $str{1}.' => '.ord($str{1})."\n"; echo $str{2}.' => '.ord($str{2})."\n"; echo $str{3}.' => '.ord($str{3})."\n"; ?> You can learn more about UTF-8 and BOM here: http://www.unicode.org/faq/utf_bom.html

« previous php.notes (#84258) next »