Bug #61054 [Fbk-Opn]: preg_match () matching end of line in text file of windows style make a mistake

2012-02-14 Thread gzpan123 at gmail dot com
Edit report at https://bugs.php.net/bug.php?id=61054edit=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: Feedback
+Status: Open
 Type:   Bug
 Package:PCRE related
 Operating System:   Windows,linux all
 PHP Version:5.3.10
 Block user comment: N
 Private report: N

 New Comment:

Test script:
---
?php
$file = fopen(test.txt,r);
while(!feof($file)){
$line = fgets($file);
preg_match('/^(.+) (.+)$/',$line,$matches);
echo $line; 
if(array_key_exists(1, $matches)  array_key_exists(2, $matches))
echo $matches[1].$matches[2];
}
fclose($file);
?
test.txt must be created in windows
abc def
ghi jklm
nop

Expected result:
--
abc def
abcdef
ghi jklm
ghijklm
nop

Actual result:
--
abc def
ghi jklm
nopjklm


Previous Comments:

[2012-02-15 01:06:29] ahar...@php.net

I don't understand the issue either. The code behaves the same way for me 
regardless of the line ending in test.txt.

Can you provide a simpler example, please?


[2012-02-12 12:42:59] ni...@php.net

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.


[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=61054edit=1


Bug #61054 [Opn]: preg_match () matching end of line in text file of windows style make a mistake

2012-02-14 Thread gzpan123 at gmail dot com
Edit report at https://bugs.php.net/bug.php?id=61054edit=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:PCRE related
 Operating System:   Windows,linux all
 PHP Version:5.3.10
 Block user comment: N
 Private report: N

 New Comment:

$matches[2] follow character CR


Previous Comments:

[2012-02-15 04:44:28] gzpan123 at gmail dot com

Test script:
---
?php
$file = fopen(test.txt,r);
while(!feof($file)){
$line = fgets($file);
preg_match('/^(.+) (.+)$/',$line,$matches);
echo $line; 
if(array_key_exists(1, $matches)  array_key_exists(2, $matches))
echo $matches[1].$matches[2];
}
fclose($file);
?
test.txt must be created in windows
abc def
ghi jklm
nop

Expected result:
--
abc def
abcdef
ghi jklm
ghijklm
nop

Actual result:
--
abc def
ghi jklm
nopjklm


[2012-02-15 01:06:29] ahar...@php.net

I don't understand the issue either. The code behaves the same way for me 
regardless of the line ending in test.txt.

Can you provide a simpler example, please?


[2012-02-12 12:42:59] ni...@php.net

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.


[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=61054edit=1


Bug #61054 [Nab]: preg_match () matching end of line in text file of windows style make a mistake

2012-02-14 Thread gzpan123 at gmail dot com
Edit report at https://bugs.php.net/bug.php?id=61054edit=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: Not a bug
 Type:   Bug
 Package:PCRE related
 Operating System:   Windows,linux all
 PHP Version:5.3.10
 Block user comment: N
 Private report: N

 New Comment:

Yes,thanks.That is it


Previous Comments:

[2012-02-15 05:19:46] ras...@php.net

Ok. here is my guess at what is confusing you.

By default PCRE uses \n to indicate the end of a line. Your files have \r\n at 
the end, so I think the only confusion you have is that your second match will 
have \r included in it and when you then print this on the console it looks 
essentially invisible.

In your latest example there, try changing your output line to this:

echo $matches[1].trim($matches[2]);

Does it make more sense now?


[2012-02-15 04:48:43] gzpan123 at gmail dot com

$matches[2] follow character CR


[2012-02-15 04:44:28] gzpan123 at gmail dot com

Test script:
---
?php
$file = fopen(test.txt,r);
while(!feof($file)){
$line = fgets($file);
preg_match('/^(.+) (.+)$/',$line,$matches);
echo $line; 
if(array_key_exists(1, $matches)  array_key_exists(2, $matches))
echo $matches[1].$matches[2];
}
fclose($file);
?
test.txt must be created in windows
abc def
ghi jklm
nop

Expected result:
--
abc def
abcdef
ghi jklm
ghijklm
nop

Actual result:
--
abc def
ghi jklm
nopjklm


[2012-02-15 01:06:29] ahar...@php.net

I don't understand the issue either. The code behaves the same way for me 
regardless of the line ending in test.txt.

Can you provide a simpler example, please?


[2012-02-12 12:42:59] ni...@php.net

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.




The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

https://bugs.php.net/bug.php?id=61054


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


[PHP-BUG] Bug #61054 [NEW]: preg_match () matching end of line in text file of windows style make a mistake

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



Bug #61054 [Opn]: preg_match () matching end of line in text file of windows style make a mistake

2012-02-11 Thread gzpan123 at gmail dot com
Edit report at https://bugs.php.net/bug.php?id=61054edit=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=61054edit=1