From:             
Operating system: Windows XP,Ubuntu 11.10
PHP version:      5.3.10
Package:          *Regular Expressions
Bug Type:         Bug
Bug description:preg_match () matching end of line in text file of windows 
style make a mistake

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 bug report at https://bugs.php.net/bug.php?id=61054&edit=1
-- 
Try a snapshot (PHP 5.4):            
https://bugs.php.net/fix.php?id=61054&r=trysnapshot54
Try a snapshot (PHP 5.3):            
https://bugs.php.net/fix.php?id=61054&r=trysnapshot53
Try a snapshot (trunk):              
https://bugs.php.net/fix.php?id=61054&r=trysnapshottrunk
Fixed in SVN:                        
https://bugs.php.net/fix.php?id=61054&r=fixed
Fixed in SVN and need be documented: 
https://bugs.php.net/fix.php?id=61054&r=needdocs
Fixed in release:                    
https://bugs.php.net/fix.php?id=61054&r=alreadyfixed
Need backtrace:                      
https://bugs.php.net/fix.php?id=61054&r=needtrace
Need Reproduce Script:               
https://bugs.php.net/fix.php?id=61054&r=needscript
Try newer version:                   
https://bugs.php.net/fix.php?id=61054&r=oldversion
Not developer issue:                 
https://bugs.php.net/fix.php?id=61054&r=support
Expected behavior:                   
https://bugs.php.net/fix.php?id=61054&r=notwrong
Not enough info:                     
https://bugs.php.net/fix.php?id=61054&r=notenoughinfo
Submitted twice:                     
https://bugs.php.net/fix.php?id=61054&r=submittedtwice
register_globals:                    
https://bugs.php.net/fix.php?id=61054&r=globals
PHP 4 support discontinued:          
https://bugs.php.net/fix.php?id=61054&r=php4
Daylight Savings:                    https://bugs.php.net/fix.php?id=61054&r=dst
IIS Stability:                       
https://bugs.php.net/fix.php?id=61054&r=isapi
Install GNU Sed:                     
https://bugs.php.net/fix.php?id=61054&r=gnused
Floating point limitations:          
https://bugs.php.net/fix.php?id=61054&r=float
No Zend Extensions:                  
https://bugs.php.net/fix.php?id=61054&r=nozend
MySQL Configuration Error:           
https://bugs.php.net/fix.php?id=61054&r=mysqlcfg

Reply via email to