PHP's preg_replace

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
quadoc
Forum Contributor
Posts: 137
Joined: Fri Jul 01, 2005 5:33 pm
Location: Atlanta, GA

PHP's preg_replace

Post by quadoc »

I've the following code that replacing every '\' with a '' in $message, but for some reasons it's giving me error. Could someone tells me what I did wrong? Thanks... :?

Code: Select all

$message = preg_replace('/\/','',$message);
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

your code is wasting time initializing the regex engine...

Code: Select all

$message = str_replace('\\','',$message);
You may want to look at stripslashes as well...
User avatar
quadoc
Forum Contributor
Posts: 137
Joined: Fri Jul 01, 2005 5:33 pm
Location: Atlanta, GA

Post by quadoc »

Thanks feyd. :)
Post Reply