PHP :: remove special characters from a string

This could be just a quick and easy help for someone who is wishing to remove special characters from some string OR wishing to just keep alpha numeric characters in the string. So here is the Regular expression for that:

preg_replace('/[^a-z0-9]/i', '_', $string)

Advertisements

4 thoughts on “PHP :: remove special characters from a string

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s