Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何删除&;nbsp;来自UTF-8字符串?_Php_Utf 8_Html Entities - Fatal编程技术网

Php 如何删除&;nbsp;来自UTF-8字符串?

Php 如何删除&;nbsp;来自UTF-8字符串?,php,utf-8,html-entities,Php,Utf 8,Html Entities,我的数据库正在返回一些字符串,如: 这是一个字符串 当字符串足够长且设置了最大宽度时,这是一个问题: <p style="width:50px">This&nbsp;is&nbsp;a&nbsp;string</p> 您有一个(我不得不从数据库输出中用十六进制编码字符串;对不起,字符串是西班牙语的) 如何应对?为什么html\u entity\u decode()不起作用?那么替换功能呢?谢谢。这很棘手,它不像替换普通字符串那样简单 试试这个

我的数据库正在返回一些字符串,如:

这是一个字符串

当字符串足够长且设置了最大宽度时,这是一个问题:

<p style="width:50px">This&nbsp;is&nbsp;a&nbsp;string</p>
您有一个(我不得不从数据库输出中用十六进制编码字符串;对不起,字符串是西班牙语的)


如何应对?为什么
html\u entity\u decode()
不起作用?那么替换功能呢?谢谢。

这很棘手,它不像替换普通字符串那样简单

试试这个

 str_replace("\xc2\xa0",' ',$str); 
或者,上述方法应该有效:

$nbsp = html_entity_decode("&nbsp;");
$s = html_entity_decode("[&nbsp;]");
$s = str_replace($nbsp, " ", $s);
echo $s;

@ref:

获取html实体,替换所需的实体并解码回:

$str = str_replace('&nbsp;', ' ', htmlentities($new));
$new = html_entity_decode($str);

html\u实体解码
。问题是,您不需要不间断的空格,而是普通的空格。只有这一行适合我:
$s=str\u replace($nbsp,“,$s)
$str = str_replace('&nbsp;', ' ', htmlentities($new));
$new = html_entity_decode($str);