如何将 - 替换为 –使用 PHP

发布于 2024-10-06 06:55:28 字数 146 浏览 0 评论 0原文

如何使用 php htmlspecialchars()- 替换为 –

$content = $_POST['content'];

How do i replace - with using php htmlspecialchars()

$content = $_POST['content'];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

请远离我 2024-10-13 06:55:28

不需要,- 不是特殊字符,因此 htmlspecialchars() 不会触及它。而且 - 甚至与 不同(- 与 –)。

如果您愿意,可以使用 str_replace()

$content = str_replace('-', '–', $_POST['content']);

You don't, - is not a special character and as such will not be touched by htmlspecialchars(). And - is not even same as (- vs. –).

You can use str_replace() if you want to:

$content = str_replace('-', '–', $_POST['content']);
哎呦我呸! 2024-10-13 06:55:28

htmlentities() 会将 转换为 –< /code> (并处理任何其他实体)。

只需确保指定正确的字符集,例如:

echo htmlentities($string, ENT_QUOTES, 'UTF-8');

htmlentities() will convert to (and take care of any other entities as well).

Just make sure you specify the correct character set, e.g.:

echo htmlentities($string, ENT_QUOTES, 'UTF-8');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文