rgrne Posted April 10, 2007 Share Posted April 10, 2007 I need to strip out non alphanumeric characters from usernames. Just stripping them out would be OK, but replacing them with some other character would be better. Is there any easy way to do this, like an equivalent of strip_tags for html characters? I'm looking into eregi and eregi_replace, but it seems like I'd have to list all possible non-alphanumeric characters and go through letter by letter. Am I missing something? Quote Link to comment Share on other sites More sharing options...
fert Posted April 10, 2007 Share Posted April 10, 2007 $str=preg_replace("/^[a-zA-z]/","a",$str); this code will replace all non letters with the letter a, but I'm not sure if it'll work because the ^ character has two uses in regex. Quote Link to comment Share on other sites More sharing options...
Glyde Posted April 10, 2007 Share Posted April 10, 2007 Should be: $cleanString = preg_replace("/[^a-z0-9]/is", "", "$%#teststring34"); Quote Link to comment Share on other sites More sharing options...
neel_basu Posted April 15, 2007 Share Posted April 15, 2007 Replace \W Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.