Php 如何删除&;nbsp;来自UTF-8字符串?
我的数据库正在返回一些字符串,如:Php 如何删除&;nbsp;来自UTF-8字符串?,php,utf-8,html-entities,Php,Utf 8,Html Entities,我的数据库正在返回一些字符串,如: 这是一个字符串 当字符串足够长且设置了最大宽度时,这是一个问题: <p style="width:50px">This is a string</p> 您有一个(我不得不从数据库输出中用十六进制编码字符串;对不起,字符串是西班牙语的) 如何应对?为什么html\u entity\u decode()不起作用?那么替换功能呢?谢谢。这很棘手,它不像替换普通字符串那样简单 试试这个
这是一个字符串
当字符串足够长且设置了最大宽度时,这是一个问题:
<p style="width:50px">This is a string</p>
您有一个(我不得不从数据库输出中用十六进制编码字符串;对不起,字符串是西班牙语的)
如何应对?为什么
html\u entity\u decode()
不起作用?那么替换功能呢?谢谢。这很棘手,它不像替换普通字符串那样简单
试试这个
str_replace("\xc2\xa0",' ',$str);
或者,上述方法应该有效:
$nbsp = html_entity_decode(" ");
$s = html_entity_decode("[ ]");
$s = str_replace($nbsp, " ", $s);
echo $s;
@ref:获取html实体,替换所需的实体并解码回:
$str = str_replace(' ', ' ', htmlentities($new));
$new = html_entity_decode($str);
html\u实体解码
。问题是,您不需要不间断的空格,而是普通的空格。只有这一行适合我:$s=str\u replace($nbsp,“,$s)代码>
$str = str_replace(' ', ' ', htmlentities($new));
$new = html_entity_decode($str);