我有一种情况,我把一个字符串传递给一个函数.我想转换& nbsp;到“”(空格),然后再传递给函数. html_entity_decode是吗?
如果不行怎么办?
我知道str_replace,但还有其他出路吗?
报价从
原文链接:/php/131095.htmlhtml_entity_decode()
手册:
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.
您可以使用str_replace()
将ascii字符#160替换为空格:
<?PHP $a = html_entity_decode('> <'); echo 'before ' . $a . PHP_EOL; $a = str_replace("\xA0",' ',$a); echo ' after ' . $a . PHP_EOL;