How to wipe special html characters like others from text using PHP?

How to erase special html characters like  others from text using PHP?

+3
source share
4 answers

.....

$newtext = html_entity_decode($your_text);

You need to delete  separately:

$newtext = str_replace(' ', '', $newtext);

If you want to delete html tagstoo, you can use:

$newtext = strip_tags($newtext);

.......

References for relevant functions:

html_entity_decode

strip_tags

str_replace

+8
source

You might want to try html_entity_decode; -)

For instance:

$html = "this is a text";
var_dump($html);
var_dump(html_entity_decode($html, ENT_COMPAT, 'UTF-8'));

You'll get:

string 'this is a text' (length=19)
string 'this is a text' (length=15)


Please note that you may need to specify a third parameter - the encoding - if you are not working with ISO-8859-1.

+3
source

, :

preg_replace("/&#?[a-z0-9]{2,8};/i", "", $text_with_special_chars); 

( html?)

+1

See html_entity_decode to convert characters to something more human-readable.

0
source

Source: https://habr.com/ru/post/1735979/


All Articles