Aargh
11-23-2011, 03:31 PM
Hello everyone
I have a problem with preg_replace(). It's probably something stupid that I simply fail to see, but I can't figure out what's wrong.
The thing is, I have a string that has a lot of information I don't need, and I use preg_replace to strip that out.
For this, I use the following code:
$regex = "'?;? ?option\['\d+'\] = '";
$replace = ", ";
echo preg_replace($regex, $replace, $string);
I tested this using http://gskinner.com/RegExr/ to be sure the regular expression isn't wrong. On that page it works exactly the way I want it to work, but when I use it in my PHP code it tells me
Warning: preg_replace() [function.preg-replace]: Unknown modifier '\' in **filename** on line 13
Can anyone tell me what I'm doing wrong, and more importantly how to do it right?
I have a problem with preg_replace(). It's probably something stupid that I simply fail to see, but I can't figure out what's wrong.
The thing is, I have a string that has a lot of information I don't need, and I use preg_replace to strip that out.
For this, I use the following code:
$regex = "'?;? ?option\['\d+'\] = '";
$replace = ", ";
echo preg_replace($regex, $replace, $string);
I tested this using http://gskinner.com/RegExr/ to be sure the regular expression isn't wrong. On that page it works exactly the way I want it to work, but when I use it in my PHP code it tells me
Warning: preg_replace() [function.preg-replace]: Unknown modifier '\' in **filename** on line 13
Can anyone tell me what I'm doing wrong, and more importantly how to do it right?