... in an ereg_replace
| 10:24 pm on Jan 9, 2007 (gmt 0)|
I'm trying to do an ereg_replace on a string that contains parenthesis, but am getting the following error:
PHP Warning: ereg_replace(): REG_EPAREN
$string = "widgets widgets ___ widgets (large widgets) widgets widgets";
$newstring = ereg_replace("___","",$string);
What is the correct way to escape a parenthesis?
| 11:28 pm on Jan 9, 2007 (gmt 0)|
there are 11 characters with special meanings: the opening square bracket [, the backslash \, the caret ^, the dollar sign $, the period or dot ., the vertical bar or pipe symbol ¦, the question mark?, the asterisk or star *, the plus sign +, the opening round bracket ( and the closing round bracket ). These special characters are often called "metacharacters".
If you want to use any of these characters as a literal in a regex, you need to escape them with a backslash.
This comes from a well known domain dedicated to
hmmmm see what I mean :)
| 11:33 pm on Jan 9, 2007 (gmt 0)|
You don't escape anything within the string itself. It is in your pattern syntax that you escape meta characters. Since you left out the pattern we cannot tell for sure, but it is definitely coming from your pattern. :)
| 5:53 am on Jan 10, 2007 (gmt 0)|
the error is generated from your pattern however the code you have posted doesn't have any problem so not sure why isn't it working... also if you just want to replace combination of udnerscores then you can use str_replace("___",'',$string);