newbie q: using eregi_replace to replace parentheses

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
auaero
Forum Newbie
Posts: 9
Joined: Wed Aug 28, 2002 9:47 am

newbie q: using eregi_replace to replace parentheses

Post by auaero »

Alright, this may be simple, but I just started using PHP yesterday. I'm trying to replace the parentheses in a string of text using eregi_replace. Here's the code:

$TableString = eregi_replace(")"," " , $TableString);

The problem comes up, as you probably guessed, when PHP hits the parentheses I want replace and I get an unbalanced parentheses error. Is there an escape character for parentheses? I tried using a backslash (liek perl -- "\)" ) but I still got the error. Any help you guys can give would be greatly appreciated.

AUaero
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Code: Select all

$TableString = "abc ) 123";
$TableString = eregi_replace('\)',' ' , $TableString);
but for replacing constant strings I suggest str_replace

Code: Select all

$TableString = "abc ) 123";
$TableString = str_replace(')',' ' , $TableString);
User avatar
auaero
Forum Newbie
Posts: 9
Joined: Wed Aug 28, 2002 9:47 am

Thanks

Post by auaero »

:oops: Thanks, Volka, there was another line with the same problem that I was forgetting about. That's why I couldn't get it too work.

AUaero
Post Reply