Does html_entity_decode replaces also? If not how to replace it?
Quote from html_entity_decode()
manual:
You might wonder why
trim(html_entity_decode(' '));
doesn't reduce the string to an empty string, that's because the' '
entity is not ASCII code 32 (which is stripped by trim()) but ASCII code 160 (0xa0) in the default ISO 8859-1 characterset.
You can use str_replace()
to replace the ascii character #160 to a space:
<?php
$a = html_entity_decode('> <');
echo 'before ' . $a . PHP_EOL;
$a = str_replace("\xA0", ' ', $a);
echo ' after ' . $a . PHP_EOL;
html_entity_decode does convert
to a space, just not a "simple" one (ASCII 32), but a non-breaking space (ASCII 160) (as this is the definition of
).
If you need to convert to ASCII 32, you still need a str_replace()
, or, depending on your situation, a preg_match("/s+", ' ', $string)
to convert all kinds of whitespace to simple spaces.
YES
See PHP manual http://php.net/manual/en/function.html-entity-decode.php.
Carefully read the Notes, maybe that s the issue you are facing:
You might wonder why trim(html_entity_decode(' ')); doesn't reduce the string to an empty string, that's because the ' ' entity is not ASCII code 32 (which is stripped by trim()) but ASCII code 160 (0xa0) in the default ISO 8859-1 characterset.