Bug #60380 [Opn->Csd]: preg_split and old version split

2012-08-30 Thread evrinoma at gmail dot com
Edit report at https://bugs.php.net/bug.php?id=60380&edit=1

 ID: 60380
 User updated by:evrinoma at gmail dot com
 Reported by:evrinoma at gmail dot com
 Summary:preg_split and old version split
-Status: Open
+Status: Closed
 Type:   Bug
 Package:*Programming Data Structures
 Operating System:   Linux CenOS5 CentOS6
 PHP Version:5.3.8
 Block user comment: N
 Private report: N

 New Comment:

Many thanks for help


Previous Comments:

[2012-08-30 19:55:06] ni...@php.net

You are dealing with two levels of unescaping here. The first is the usual for 
string, the second is additionally done by PCRE.

E.g. if you write "" the actually resulting string will just be "\\" 
(because \\ is unescaped to \). This is then passed to PCRE, which itself again 
does unescaping, so the \\ is turned into \. That's why you need four 
backslashes to produce one literal backslash in a regular expression.

In your particular case three work too, but only because the following 
character does not form an escape sequence.


[2012-08-30 19:24:38] cjbf at cam dot ac dot uk

Three \s are needed to match one \. Could that at least be documented if it's 
not wrong?
$text='AA\\nB and B\r';// contains \n and \r
print_r(preg_split('/\\\n|\\\r/', $text));
gives
Array
(
[0] => AA
[1] => B and B
[2] => 
)


[2012-08-30 19:02:43] cjbf at cam dot ac dot uk

Put simply, preg_split treats "\\" wrongly. It ought to search for an actual 
"\" but never matches it.

----------------
[2011-11-25 07:15:00] evrinoma at gmail dot com

Description:

--splite--- 
 array[0]=0123456789-- 
 array[1]=qwertyuiop-- 
 array[2]=9876543210-- 
 array[3]=poiuytrewq-- 
 array[4]=0123456789-- 
 array[5]=asdfghjkl-- 
 --preg_splite-- 
 array[0]=0123456789\qwertyuiop-- <<<<<<<<< ???
 array[1]=9876543210-- 
 array[2]=poiuytrewq-- 
 array[3]=0123456789-- 
 array[4]=asdfghjkl-- 
 array[5]=-- 
 ---

Test script:
---


 BUG 


\n");

$date="0123456789\\qwertyuiop 9876543210.poiuytrewq:0123456789 asdfghjkl";
$var = split( "[-\\. :]",$date );

printf(" array[0]=%s-- \n",$var[0]);
printf(" array[1]=%s-- \n",$var[1]);
printf(" array[2]=%s-- \n",$var[2]);
printf(" array[3]=%s-- \n",$var[3]);
printf(" array[4]=%s-- \n",$var[4]);
printf(" array[5]=%s-- \n",$var[5]);

printf(" --preg_splite-- \n");

$var = preg_split( "#[-\\. :]#",$date);

printf(" array[0]=%s-- \n",$var[0]);
printf(" array[1]=%s-- \n",$var[1]);
printf(" array[2]=%s-- \n",$var[2]);
printf(" array[3]=%s-- \n",$var[3]);
printf(" array[4]=%s-- \n",$var[4]);
printf(" array[5]=%s-- \n",$var[5]);
printf(" --- \n");

?>










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


[PHP-BUG] Bug #60380 [NEW]: preg_split and old version split

2011-11-24 Thread evrinoma at gmail dot com
From: 
Operating system: Linux CenOS5 CentOS6
PHP version:  5.3.8
Package:  *Programming Data Structures
Bug Type: Bug
Bug description:preg_split and old version split

Description:

--splite--- 
 array[0]=0123456789-- 
 array[1]=qwertyuiop-- 
 array[2]=9876543210-- 
 array[3]=poiuytrewq-- 
 array[4]=0123456789-- 
 array[5]=asdfghjkl-- 
 --preg_splite-- 
 array[0]=0123456789\qwertyuiop-- < ???
 array[1]=9876543210-- 
 array[2]=poiuytrewq-- 
 array[3]=0123456789-- 
 array[4]=asdfghjkl-- 
 array[5]=-- 
 ---

Test script:
---


 BUG 


\n");

$date="0123456789\\qwertyuiop 9876543210.poiuytrewq:0123456789 asdfghjkl";
$var = split( "[-\\. :]",$date );

printf(" array[0]=%s-- \n",$var[0]);
printf(" array[1]=%s-- \n",$var[1]);
printf(" array[2]=%s-- \n",$var[2]);
printf(" array[3]=%s-- \n",$var[3]);
printf(" array[4]=%s-- \n",$var[4]);
printf(" array[5]=%s-- \n",$var[5]);

printf(" --preg_splite-- \n");

$var = preg_split( "#[-\\. :]#",$date);

printf(" array[0]=%s-- \n",$var[0]);
printf(" array[1]=%s-- \n",$var[1]);
printf(" array[2]=%s-- \n",$var[2]);
printf(" array[3]=%s-- \n",$var[3]);
printf(" array[4]=%s-- \n",$var[4]);
printf(" array[5]=%s-- \n",$var[5]);
printf(" --- \n");

?>





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