From: Operating system: PHP version: Irrelevant Package: PCRE related Bug Type: Feature/Change Request Bug description:enhance / change newline behavior
Description: ------------ At the moment (PHP bundled) PCRE is build with the default "#define NEWLINE 10". As a result "$" means "\n" but not e.g. "\r\n" and "\r" remains as part of the match. This is unexpected for some people, especially on Windows. See the example below. There are 3 solutions: 1) Building PCRE with "#define NEWLINE -2", or with "#define NEWLINE -1" (because PCRE is still build with Unicode support) 2) Adding a INI option like "pcre.newline=any" 3) Making PCRE_NEWLINE_ANY, PCRE_NEWLINE_CR, PCRE_NEWLINE_CRLF, PCRE_NEWLINE_LF available to the userland (maybe as pattern modifier), like you can do this with C using the PCRE library. (Well, 1) is not essential if 2) and 3) is available) Test script: --------------- <?php $str = "line1\r\nline2\r\nline3\r\n"; preg_match_all('/.+/', $str, $res); var_dump($res); ?> Expected result: ---------------- array(1) { [0]=> array(3) { [0]=> string(5) "line1" [1]=> string(5) "line2" [2]=> string(5) "line3" } } Actual result: -------------- array(1) { [0]=> array(3) { [0]=> " string(6) "line1 [1]=> " string(6) "line2 [2]=> " string(6) "line3 } } -- Edit bug report at http://bugs.php.net/bug.php?id=54223&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=54223&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=54223&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=54223&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=54223&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=54223&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=54223&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=54223&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=54223&r=needscript Try newer version: http://bugs.php.net/fix.php?id=54223&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=54223&r=support Expected behavior: http://bugs.php.net/fix.php?id=54223&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=54223&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=54223&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=54223&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=54223&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=54223&r=dst IIS Stability: http://bugs.php.net/fix.php?id=54223&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=54223&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=54223&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=54223&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=54223&r=mysqlcfg