gpt4 book ai didi

php - html_entity_decode 也会替换吗?如果不行怎么换?

转载 作者:技术小花猫 更新时间:2023-10-29 12:35:41 26 4
gpt4 key购买 nike

我有一种情况,我将一个字符串传递给一个函数。我想在将   传递给函数之前将其转换为“”(空格)。 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;

关于php - html_entity_decode 也会替换吗?如果不行怎么换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6275380/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com