note 78308 modified in function.fopen by danbrown
| From: | danbrown@php.net | Date: | Mon, 08 Jun 2009 23:34:03 +0000 |
| Subject: | note 78308 modified in function.fopen by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-156545@lists.php.net to get a copy of this message | ||
The UTF-8 BOM is optional. PHP does not ignore it if it is present when reading UTF-8 encoded data.
Here is a function that skips the BOM, if it exists.
<?php
// Reads past the UTF-8 bom if it is there.
function fopen_utf8 ($filename, $mode) {
$file = @fopen($filename, $mode);
$bom = fread($file, 3);
if ($bom != b"\xEF\xBB\xBF")
rewind($file, 0);
else
echo "bom found!\n";
return $file;
}
?>
--was--
The UTF-8 BOM is optional. PHP does not ignore it if it is present when reading UTF-8 encoded data.
Here is a function that skips the BOM, if it exists.
// Reads past the UTF-8 bom if it is there.
function fopen_utf8 ($filename, $mode) {
$file = @fopen($filename, $mode);
$bom = fread($file, 3);
if ($bom != b"\xEF\xBB\xBF")
rewind($file, 0);
else
echo "bom found!\n";
return $file;
}
http://php.net/manual/en/function.fopen.php