On Tue, 2010-06-22 at 13:35 -0400, Rick Dwyer wrote: > Thanks to everyone who responded. > > Regarding the myriad of choices, isn't Ashley's, listed below, the one > most like to guarantee the cleanest output of just letters and numbers? > > > --Rick > > > On Jun 22, 2010, at 11:44 AM, Ashley Sheridan wrote: > > > On Tue, 2010-06-22 at 11:40 -0400, Rick Dwyer wrote: > > Use preg_replace(), which allows you to use a regex to specify what > > you want to match: > > > > $find = '/[^a-z0-9]/i'; > > $replace = '_'; > > $new_string = preg_replace($find, $replace, $old_string); > > > > Thanks, > > Ash > > http://www.ashleysheridan.co.uk > > > > > It is clean, but as Richard mentioned, it won't handle strings outside of the traditional 128 ASCII range, so accented characters and the like will be converted to an underscore. Also, spaces might become an issue. However, if you are happy that your input won't go beyond the a-z0-9 range, then it should do what you need. Thanks, Ash http://www.ashleysheridan.co.uk