我的数据库正在返回一些字符串,如:This is a string
当字符串足够长并且您设置了最大宽度时,这是一个问题:
<p style="width:50px">This is a string</p>
为了搭车
我尝试使用以下过滤器但没有成功:$new = preg_replace("/ /i", " ", $str);
$new = str_replace(' ', ' ', $str);
$new = html_entity_decode($str);
您有一个 PHP fiddle to see this in action (我不得不将数据库输出中的字符串编码为十六进制;该字符串是西类牙语的,抱歉)。
如何处理?为什么
html_entity_decode()
不管用?那么替换功能呢?谢谢。
最佳答案
这变得棘手,它不像替换普通字符串那么简单。
尝试这个。
str_replace("\xc2\xa0",' ',$str);
或者这个,上面应该工作:
$nbsp = html_entity_decode(" ");
$s = html_entity_decode("[ ]");
$s = str_replace($nbsp, " ", $s);
echo $s;
@ref: https://moovwebconfluence.atlassian.net/wiki/pages/viewpage.action?pageId=1081435
关于php - 如何从 UTF-8 字符串中删除 ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28704562/