Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Newbie Confusion with str_replace



10:41 am on May 11, 2006 (gmt 0)

10+ Year Member

Hi all,

I am trying to edit out the words enclosed in round brackets e.g. ( widget ) from my data with the help of str_replace function.

The code I am using is:

$simple = str_replace('(WIDGET)', '', $simple);

As the words in round brackets are many, I ended up having a long series of str_replace statements in my code which have slowed down my script significantly. I wondered that there should be an easy way of doing this in PHP and searched a bit. I came across preg_replace function which is quite close to what I want but could not figure out how to write the pattern so that it can delete all the text that is enclosed in a round bracket.

I must be the oldest newbie to php as I have been playing with it for last two three years but never learnt it systematically. Any help here will be well appreciated :-)

Longhaired Genius

11:18 am on May 11, 2006 (gmt 0)

10+ Year Member

$simple = preg_replace('/\(.*\)/U', '', $simple);


11:45 am on May 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

Actaully, I'd try:


This '[^\)]' means that it will get any char except for a closing bracket )


Featured Threads

Hot Threads This Week

Hot Threads This Month