Page 1 of 1

preg_replace '[' , ']'

Posted: Tue May 01, 2007 11:52 pm
by nwp
I am using this code

Code: Select all

<?php
$sub = 'My foo[0]';
$replace = 'bar[0]';
echo preg_replace('/foo[0]/', $replace, $sub);
?>
And its outputing
My foo[0]
instead of My bar[0].
Is it for the '[' , ']' ?
If yes how to do it ??

Posted: Wed May 02, 2007 12:01 am
by feyd
The brackets are special characters in regular expressions. They must be escaped if you wish to have their literal character meaning.