From: soapergem at gmail dot com Operating system: Windows XP PHP version: 5.3.0 PHP Bug Type: Filesystem function related Bug description: fgets reads the UTF-8 Byte Order Mark literally
Description: ------------ When text files are saved with UTF-8 encoding, a few characters are saved at the front called the "Byte Order Mark" (read more about it on Wikipedia). They are supposed to remain hidden and just be used as meta-data to indicate that the file is saved with UTF-8 formatting. Their hex values are EF BB BF, which is represented in ASCII by "". The trouble is that when you read in a UTF-8 text file with either fgets or fgetcsv, PHP misinterprets the BOM as literal text and includes it with all the other text. Reproduce code: --------------- <?php if ( $fp = fopen('ut8_text_file.txt') ) { echo fgets($fp); fclose($fp); } ?> Expected result: ---------------- Whatever text is saved on the first line of the text file. Actual result: -------------- Whatever text is saved on the first line of the text file. -- Edit bug report at http://bugs.php.net/?id=49350&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=49350&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=49350&r=trysnapshot53 Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=49350&r=trysnapshot60 Fixed in SVN: http://bugs.php.net/fix.php?id=49350&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=49350&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=49350&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=49350&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=49350&r=needscript Try newer version: http://bugs.php.net/fix.php?id=49350&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=49350&r=support Expected behavior: http://bugs.php.net/fix.php?id=49350&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=49350&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=49350&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=49350&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=49350&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=49350&r=dst IIS Stability: http://bugs.php.net/fix.php?id=49350&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=49350&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=49350&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=49350&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=49350&r=mysqlcfg