How to wipe html special chars like and others from text with the help of PHP?
views:
39answers:
4
+3
A:
.....
$newtext = html_entitiy_decode($your_text);
You got to remove separately:
$newtext = str_replace(' ', '', $newtext);
If you want to remove html tags too, you can use:
$newtext = strip_tags($newtext);
.
Relevant Functions Reference:
Sarfraz
2010-03-08 18:33:16
+1
A:
You might want to try with html_entity_decode ;-)
For example :
$html = "this is a text";
var_dump($html);
var_dump(html_entity_decode($html, ENT_COMPAT, 'UTF-8'));
Will give you :
string 'this is a text' (length=19)
string 'this is a text' (length=15)
Note that you might need to specify the third parameter -- the charset -- if you are not working with ISO-8859-1.
Pascal MARTIN
2010-03-08 18:33:29
A:
Look at html_entity_decode to convert the characters to something more human-readable.
Mike Cialowicz
2010-03-08 18:33:31
+1
A:
If he meant removing, here's how to do it:
preg_replace("/&#?[a-z0-9]{2,8};/i", "", $text_with_special_chars);
(Found at http://stackoverflow.com/questions/657643/how-to-remove-html-special-chars-in-php)
AleGore
2010-03-08 18:58:12