note 46874 added to function.file-get-contents
| From: | NedBaldessin at osu1 dot php dot net | Date: | Tue, 26 Oct 2004 16:32:18 +0000 |
| Subject: | note 46874 added to function.file-get-contents | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-79134@lists.php.net to get a copy of this message | ||
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
----
Manual Page -- http://www.php.net/manual/en/function.file-get-contents.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+46874
Delete -- http://master.php.net/manage/user-notes.php?action=delete+46874&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+46874&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+46874&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+46874&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+46874&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+46874&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+46874&report=yes
Search -- http://master.php.net/manage/user-notes.php