Page 1 of 1

newbie q: using eregi_replace to replace parentheses

Posted: Wed Aug 28, 2002 9:47 am
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

Posted: Wed Aug 28, 2002 9:56 am
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);

Thanks

Posted: Wed Aug 28, 2002 10:03 am
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