我有一种情况,我将一个字符串传递给一个函数。我想在将
传递给函数之前将其转换为“”(空格)。 html_entity_decode
可以吗?
如果不行怎么办?
我知道 str_replace
但还有其他出路吗?
最佳答案
引自 html_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;
关于php - html_entity_decode 也会替换吗?如果不行怎么换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6275380/