Jump to content

Archived

This topic is now archived and is closed to further replies.

bcamp1973

stripping all non alpha-numeric characters from string

Recommended Posts

ok, i want to strip all instances of "\r\n", "\r", "\n","\t" and non-alpha numeric characters from a string. in my searching through the PHP manual there seems to be a lot of options...such as str_replace, preg_replace(), ereg_replace() etc. i need something that's fast an efficient and i'm guessing i'll have to use regex of some form but it's not something i'm very knowledgable of.  any suggestions?

Share this post


Link to post
Share on other sites
Take the reverse approach, only match those characters you want to retrieve. ;-)

Share this post


Link to post
Share on other sites
i like this approach:
[code]
<?php
$String = preg_replace('|[^a-z0-9]|i', '', $String);
echo $String;
?>
[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.