Tariko Nigan
Tariko Nigan

Reputation: 31

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

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

Upvotes: 3

Views: 5309

Answers (2)

Sarfraz
Sarfraz

Reputation: 382706

.....

$newtext = html_entity_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

Upvotes: 9

Pascal MARTIN
Pascal MARTIN

Reputation: 401012

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`.

Upvotes: 4

Related Questions