html_entity_decode是否替换& nbsp;也?如果不是如何更换它? [英] Does html_entity_decode replaces   also? If not how to replace it?

查看:161
本文介绍了html_entity_decode是否替换& nbsp;也?如果不是如何更换它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一种情况是我将一个字符串传递给一个函数。我想在将它传递给函数之前将& nbsp; 转换为(空格)。 html_entity_decode 是否可以做到这一点?

I have a situation where I am passing a string to a function. I want to convert   to " " (a blank space) before passing it to function. Does html_entity_decode does it?

如果不是如何操作的话?

If not how to do it?

我知道 str_replace code>但有没有其他出路?

I am aware of str_replace but is there any other way out?

推荐答案

来自 html_entity_decode() 手册:


您可能想知道为什么
trim(html_entity_decode('& nbsp;'));
不会将字符串减少为空的
字符串,这是因为'& nbsp;'
实体不是ASCII在默认的ISO 8859-1
字符集中使用代码32(这是trim())剥离的
,而是ASCII码160
(0xa0)。

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替换为空格:

You can use str_replace() to replace the ascii character #160 to a space:

<?php
$a = html_entity_decode('>&nbsp;<');
echo 'before ' . $a . PHP_EOL;
$a = str_replace("\xA0", ' ', $a);
echo ' after ' . $a . PHP_EOL;

这篇关于html_entity_decode是否替换&amp; nbsp;也?如果不是如何更换它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆