homepage Welcome to WebmasterWorld Guest from 54.226.136.179
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Escaping parenthesis
... in an ereg_replace
panic

10+ Year Member



 
Msg#: 3213949 posted 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?

 

henry0

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



 
Msg#: 3213949 posted 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
"regular-Epressions"
hmmmm see what I mean :)

eelixduppy

WebmasterWorld Senior Member eelixduppy us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 3213949 posted 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. :)

female designer

5+ Year Member



 
Msg#: 3213949 posted 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);

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved