Page 1 of 1

Strange bug (?) with \s

Posted: Mon Jul 20, 2009 10:33 am
by alfmarius
Hello, can any one tell me why the first match below fails, while the second succeed in snatching "Hello world" ?
Only difference is a parentheses around the first \s, but i thought these two were the same:

'\s*' = '(\s)*' ..same no?

Code: Select all

$content = <<<QQQ
                  <td width="126"><font color="D7D7D7" size="1" face="Verdana, Arial, Helvetica, sans-serif">
                    Hello world
                  </font></td>
QQQ;
$string1 = '.*<td .*<font .*sans-serif">\s*(\S.*\S)\s*<\/font><\/td>';
preg_match_all("/$string1/Ui", $content, $matches1);
 
$string2 = '.*<td .*<font .*sans-serif">(\s)*(\S.*\S)\s*<\/font><\/td>'; // same as $string1, but parentheses added to the first \s
preg_match_all("/$string2/Ui", $content, $matches2);
 
print_r($matches1);
print_r($matches2);
Result:

Code: Select all

 
Array(
    [0] => Array()
    [1] => Array()
)
Array(
    [0] => Array(
            [0] =>                   <td width="126"><font color="D7D7D7" size="1" face="Verdana, Arial, Helvetica, sans-serif">
                    Hello world
                  </font></td>
        )
    [1] => Array(
            [0] =>
        )
    [2] => Array(
            [0] => Hello world
        )
 ) 

Re: Strange bug (?) with \s

Posted: Mon Jul 20, 2009 11:29 am
by prometheuzz
When I execute your code, I get the following output:

Code: Select all

Array
(
    [0] => Array
        (
            [0] =>                   <td width="126"><font color="D7D7D7" size="1" face="Verdana, Arial, Helvetica, sans-serif">
                    Hello world
                  </font></td>
        )
 
    [1] => Array
        (
            [0] => Hello world
        )
 
)
Array
(
    [0] => Array
        (
            [0] =>                   <td width="126"><font color="D7D7D7" size="1" face="Verdana, Arial, Helvetica, sans-serif">
                    Hello world
                  </font></td>
        )
 
    [1] => Array
        (
            [0] =>  
        )
 
    [2] => Array
        (
            [0] => Hello world
        )
 
)
I tested it on three different machines: all produce this same output.

Re: Strange bug (?) with \s

Posted: Mon Jul 20, 2009 12:03 pm
by alfmarius
prometheuzz wrote:I tested it on three different machines: all produce this same output.
How very odd! ..but I got it working on the third server I tried. However, these did not work:

PHP Version 5.2.6-1+lenny3 -> PCRE Library Version 7.6 2008-01-28
PHP Version 5.2.0-8+etch13 -> PCRE Library Version 6.7.7.4 2008-02-18

Though this worked:

PHP Version 5.2.9-0.dotdeb.1 -> PCRE Library Version 7.6 2008-01-28

couldnt find any info on bugs.php.net either..

What version did you test on?

Re: Strange bug (?) with \s

Posted: Mon Jul 20, 2009 12:49 pm
by prometheuzz
alfmarius wrote:...

What version did you test on?
PHP versions PHP 5.2.6-3ubuntu4.1 with Suhosin-Patch 0.9.6.2 and twice PHP 5.2.7 (no shell access, so don't have more much info on those), all have PCRE Library Version 7.8 2008-09-05.

HTH