icetohot Posted February 25, 2005 Share Posted February 25, 2005 how do I replace all characters in a string that aren't in a certain characters set (ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwzyz1234567890-_.)? thanks Link to comment https://www.neowin.net/forum/topic/290044-php-remove-unwanted-characters-from-a-string/ Share on other sites More sharing options...
0 spydoor Posted February 25, 2005 Share Posted February 25, 2005 don't know much PHP, but use regular expressions ereg_replace http://us4.php.net/regex for your example it would be something like ereg_replace("[^A-Za-z0-9-_.]", "", $string); replace everything not mathced by regexp with blank (you may have to handle the . by escaping it ?????) Link to comment https://www.neowin.net/forum/topic/290044-php-remove-unwanted-characters-from-a-string/#findComment-585533353 Share on other sites More sharing options...
0 icetohot Posted February 25, 2005 Author Share Posted February 25, 2005 spydoor said: don't know much PHP, but use regular expressionsereg_replace http://us4.php.net/regex for your example it would be something like ereg_replace("[^A-Za-z0-9-_.]", "", $string); replace everything not mathced by regexp with blank (you may have to handle the . by escaping it ?????) 585533353[/snapback] thanks! I ended up using ereg_replace("[^[:alnum:]+.+_+-]", "_", $string); :D Link to comment https://www.neowin.net/forum/topic/290044-php-remove-unwanted-characters-from-a-string/#findComment-585533827 Share on other sites More sharing options...
Question
icetohot
how do I replace all characters in a string that aren't in a certain characters set (ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwzyz1234567890-_.)?
thanks
Link to comment
https://www.neowin.net/forum/topic/290044-php-remove-unwanted-characters-from-a-string/Share on other sites
2 answers to this question
Recommended Posts