Re: Removing special characters

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Computer Programmer wrote:
Is there a PHP built-in function to retrieve only the alphanumeric characters from a given string?

I know that I can check for alphanumeric characters using the function ctype_alphanum () but it won't retrieve the alphanum characters.

I also know that I can use str_replace to replace an array of special characters such as the example below:

$str = "I*m using <html tags> with special/chars like | how to get rid of it???";
$removeChars = array ('*','?','|','>','<','/','\\');
$str = str_replace ($removeChars, "", $str);

However, could there be a specific function for just retrieving alphanumeric characters? or a specific function for just stripping special characters? Or maybe a better way to do those things from the example given above?

$str = preg_replace('/[^a-z0-9]/i', '', $str);

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux