Edit report at https://bugs.php.net/bug.php?id=61054&edit=1
ID: 61054 User updated by: gzpan123 at gmail dot com Reported by: gzpan123 at gmail dot com Summary: preg_match () matching end of line in text file of windows style make a mistake Status: Open Type: Bug Package: *Regular Expressions -Operating System: Windows XP,Ubuntu 11.10 +Operating System: Windows,linux all PHP Version: 5.3.10 Block user comment: N Private report: N New Comment: windows,linux all meet this bug Previous Comments: ------------------------------------------------------------------------ [2012-02-11 09:42:45] gzpan123 at gmail dot com Description: ------------ function:preg_ match() when processing text file of windows style like blow example,it get wrong the $matches[2] behind follow a character <CR>, ---- Create a text file(test.txt) in windowsï¼Content: hello guo hi jason test Test script: --------------- <?php $file = fopen("test.txt","r"); while(!feof($file)){ $line = fgets($file); preg_match('/^(.+) (.+)$/',$line,$matches); print_r($matches); echo $line; echo $matches[1].$matches[2]; } fclose($file); ?> Expected result: ---------------- Array ( [0] => hello guo [1] => hello [2] => guo ) hello guo helloguo Array ( [0] => hi jason [1] => hi [2] => jason ) hi jason hijason Array ( ) test Actual result: -------------- hello guo Array ( [0] => hello guo [1] => hello [2] => guo ) hi jason Array ( [0] => hi jason [1] => hi [2] => jason ) testArray ( ) test ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=61054&edit=1