加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – html_entity_decode代替?也?如果没有怎么替换呢?

发布时间:2020-12-13 14:06:57 所属栏目:PHP教程 来源:网络整理
导读:我有一种情况,我把一个字符串传递给一个函数.我想转换 nbsp;到“”(空格),然后再传递给函数. html_entity_decode是吗? 如果不行怎么办? 我知道str_replace,但还有其他出路吗? 报价从 html_entity_decode() 手册: You might wonder why trim(html_entity_
我有一种情况,我把一个字符串传递给一个函数.我想转换& nbsp;到“”(空格),然后再传递给函数. 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('>&nbsp;<');
echo 'before ' . $a . PHP_EOL;
$a = str_replace("xA0",' ',$a);
echo ' after ' . $a . PHP_EOL;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读