这可能是一个愚蠢的问题,但我真的想不出来……我需要将字符串转换为html实体,让我们举个例子:
"cTm❂oNe“
如果我使用http://www.freeformatter.com/html-escape.html#ad-output转换它,我会得到:"cTm ❂ oNe",这是我需要的,但如果我使用php:http://sandbox.onlinephpfunctions.com/
$x = 'cTm ❂ oNe';
echo htmlentities($x);在CLI中也尝试过:
$ cat test2; echo ""; echo ""; php test2
<?php
$x = 'cTm ❂ oNe';
echo htmlentities($x);
?>
cTm ❂ oNe如果没有成功,我在这里做错了什么?谢谢!
$ php -v
PHP 5.4.45-0+deb7u2 (cli) (built: Oct 17 2015 08:26:31)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
with the ionCube PHP Loader (enabled) + Intrusion Protection from ioncube24.com (unconfigured) v5.0.15, Copyright (c) 2002-2015, by ionCube Ltd.发布于 2015-12-18 23:05:39
根据有关htmlentities函数的文档,PHP5.6和更高版本使用UTF8编码,但更早的版本使用ISO8859-1。您可能需要使用指定编码的可选参数来调用它。
$x = 'cTm ❂ oNe';
echo htmlentities($x, ENT_QUOTES, "UTF-8");https://stackoverflow.com/questions/34358348
复制相似问题