Re: Stripping Characters

From: Date: Tue, 22 Jun 2010 16:19:08 +0000
Subject: Re: Stripping Characters
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-306313@lists.php.net to get a copy of this message
On Tue, Jun 22, 2010 at 9:40 AM, Rick Dwyer <rpdwyer@earthlink.net> wrote: > Hello List. > > I need to remove characters from a string and replace them with and > underscore. > > So instead of having something like: > > $moditem = str_replace("--","_","$mystring"); > $moditem = str_replace("?","_","$mystring"); > $moditem = str_replace("!","_","$mystring"); > ....etc. > > For every possible character I can think of, is there a way to simply omit > any character that is not an alpha character and not a number value from 0 > to 9? > check the docs, the first parameter may be an array of multiple needles, e.g. $moditem = str_replace(array('-', '?', '!'), '_', $mystring); you could likely do something more elegant w/ preg_replace() tho. -nathan

« previous php.general (#306313) next »