【发布时间】:2010-11-07 03:28:02
【问题描述】:
我正在尝试将特殊字符转换为 html 以使其正常显示。
有人可以帮助我吗?如何在 php 行下方应用 htmlspecialchars()
<?php echo $xcityid>0?$upperCase=strtoupper(str_replace("-", " ", "$xcityname")):"testing"; ?>
【问题讨论】:
我正在尝试将特殊字符转换为 html 以使其正常显示。
有人可以帮助我吗?如何在 php 行下方应用 htmlspecialchars()
<?php echo $xcityid>0?$upperCase=strtoupper(str_replace("-", " ", "$xcityname")):"testing"; ?>
【问题讨论】:
你可以改变你的语法如下:
<?php echo ($xcityid > 0) ? htmlspecialchars(strtoupper(str_replace("-", " ", "$xcityname"))) : "testing"; ?>
【讨论】:
试试这个:
<?= ($xcityid > 0) ? htmlspecialchars(strtoupper(str_replace("-", " ", $xcityname))) : "testing"; ?>
【讨论】:
setlocale 来设置您正在运行的语言环境,例如setlocale(LC_CTYPE, "fr_FR") 法语。请注意,这取决于所安装的语言环境。
htmlentities。 htmlspecialchars 只会转换一小部分受限制的字符(仅 &、"、'、)。htmlentities 转换所有内容。您还需要告诉它您使用什么编码'正在使用。试试这个作为测试:htmlentities("Golléré")。如果你得到Goll&Atilde;&copy;r&Atilde;&copy;,那么它没有使用正确的编码。对我来说,htmlentities("Golléré", ENT_COMPAT, "UTF-8") 返回Goll&eacute;r&eacute;,这是正确的!