Edit report at https://bugs.php.net/bug.php?id=61054&edit=1

 ID:                 61054
 Comment by:         ni...@php.net
 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,linux all
 PHP Version:        5.3.10
 Block user comment: N
 Private report:     N

 New Comment:

I don't really understand the issue you have from your example, but in general 
LF is the compile-default linebreak for PCRE. If you want to use a different 
linebreak character you can either compile PCRE with the appropriate option or 
specify a control option like (*CRLF) before your regular expression.


Previous Comments:
------------------------------------------------------------------------
[2012-02-11 09:47:27] gzpan123 at gmail dot com

windows,linux all meet this bug

------------------------------------------------------------------------
[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

Reply via email to