help on preg_replace() please

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
helloise
Forum Commoner
Posts: 31
Joined: Tue Sep 21, 2010 4:20 am

help on preg_replace() please

Post by helloise »

i have:

Code: Select all

$msg = ereg_replace("[^A-z0-9]"," ",$msg);
$msg = ereg_replace("  "," ",$msg);
$msg = ereg_replace("    "," ",$msg);
how will i apply preg_replace please???
thank you
User avatar
tr0gd0rr
Forum Contributor
Posts: 305
Joined: Thu May 11, 2006 8:58 pm
Location: Utah, USA

Re: help on preg_replace() please

Post by tr0gd0rr »

The first one translates pretty well, but I do think you may want `a-zA-Z` instead of `A-z`. So for the first one, keep in mind that preg_* patterns must begin and end with a special character (traditionally a forward slash). The second two statements could be done with str_replace() since no patterns are being used.
Post Reply