RE: [PHP] preg_replace wierdness

2002-11-22 Thread John W. Holmes
> Code snippet ->
>  
> header('Content-type: text/plain');
> 
> $foo = ' ';
> 
> echo "$foo\n";
> 
> 
> $path = '../../../';
> $bar = preg_replace('/()/', "$1" . $path . "$2",
$foo);
> 
> echo $bar;

It's being greedy. Your pattern is matching

( )

and inserting $path between the two.

Use

$bar = preg_replace('/()/U',"$1" . $path . "$2", $foo);

Quote:
U (PCRE_UNGREEDY)
This modifier inverts the "greediness" of the quantifiers so that they
are not greedy by default, but become greedy if followed by "?". It is
not compatible with Perl. It can also be set by a (?U) modifier setting
within the pattern. 


---John Holmes...



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] preg_replace wierdness

2002-11-22 Thread Gerard Samuel
Code snippet ->


header('Content-type: text/plain');

$foo = ' ';

echo "$foo\n";


$path = '../../../';
$bar = preg_replace('/()/', "$1" . $path . "$2", $foo);

echo $bar;

?>

The second image doesn't get affected by preg_replace().  But if I break 
$foo into multiple lines like ->
$foo = '
   ';

It works...
Any tips would be appreciated...
Thanks

--
Gerard Samuel
http://www.trini0.org:81/
http://dev.trini0.org:81/



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php