Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove all non-alphanumeric characters in string

Status
Not open for further replies.

MSRez

Programmer
Dec 22, 2004
57
EU
Is there any easy way to remove ALL non-alphanumeric characters in a string regardless of what they are?

I couldn't find a function that does this which is quite surprising.
 
Ok, turns out there isn't already a function for it but it's simple anyway.

Code:
$string = preg_replace ("/[^a-z 0-9]/i",'',$string);

Note: retains spaces in the string.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top