tags:

views:

39

answers:

4

How to wipe html special chars like   and others from text with the help of PHP?

+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:

html_entity_decode

strip_tags

str_replace

Sarfraz
+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
A: 

Look at html_entity_decode to convert the characters to something more human-readable.

Mike Cialowicz
+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