PDA

View Full Version : PCRE and preg_replace



james438
07-11-2007, 05:55 PM
Hi,

another PCRE question for you. This is not important either. is there a way to replace a whitespace with a whitespace? for example


$string="today is";
preg_replace("/\s/","/\s/",$string);
echo $string;

what I am getting when I echo the string is: today/\s/is

This is a low priority question for me. I am just curious :)

Thanks for reading!

mwinter
07-11-2007, 06:03 PM
$string="today is";
preg_replace("/\s/","/\s/",$string);
echo $string;

The second argument to preg_replace (http://uk.php.net/manual/en/function.preg-replace.php) is a formatted string, not a regular expression-containing string. Use literal white space in the second argument.

Hope that helps

james438
07-11-2007, 08:43 PM
yep, cool, thanks. I was wondering why it wasn't replacing a regular expression string with another one.