Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Escaping parenthesis

... in an ereg_replace

10:24 pm on Jan 9, 2007 (gmt 0)

Preferred Member

10+ Year Member

joined:June 16, 2003
votes: 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)

Senior Member from FR 

WebmasterWorld Senior Member henry0 is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Apr 19, 2003
votes: 9

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)

Senior Member

joined:Nov 12, 2005
votes: 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)

New User

10+ Year Member

joined:Dec 19, 2006
votes: 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);

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members