I have searched around for a method to remove all special characters (question marks, commas etc.) from some text, but can't seem to find one is there one which will turn it into plain text.
Sample input: 'this is a question, do you like it?'
Sample output: 'this is a question do you like it'
Have tried php.net but you guys will probaby know better.
Thanks very much, tom
remove special chars
Moderator: General Moderators
I would probably use str_replace()
It will output "this is a question do you like it"
I dont know much php but at least its a start! and theres only a handful of special characters like that i think.
Code: Select all
$string = "this is a question, do you like it?";
$string = str_replace(',', '', $string);
$string = str_replace('?', '', $string);I dont know much php but at least its a start! and theres only a handful of special characters like that i think.
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
Code: Select all
preg_replace('~[^\w\d\s]~i', '', $str);