关于php:将特殊字符转换为HTML实体,为什么或为什么不? | 珊瑚贝

Converting special characters into HTML entities, why or why not?


我想知道,最佳做法是什么。将所有 utf-8 特殊字符转换为 HTML 实体或仅转义


Are there downsides (or upsides) to escaping all characters vs only the minimum necessary?

现在不需要转换 <>&”‘ 之外的任何字符(如 htmlspecialchars() 所做的那样)。如果页面的字符集配置正确,那么使用原生 UTF-8 字符(或您选择的任何字符集)都没有问题。将它们转换为实体没有任何优势。它们有时被用作字符集问题的错误解决方法,但这几乎不是一个好主意。

  • 你说 htmlentities,但是你链接到 htmlspecialchars。但我明白你的意思。那么 \\'<?xml\\’ 标头呢,有什么建议吗?
  • @Paul 已修复,谢谢!关于 XML 标头,我不确定我是否理解您的意思,您希望在什么情况下发送它?
  • html 文档的第一行,w3 说使用 `<?xml version=”1.0″ encoding=”UTF-8″ ?>` 但是市长网站不使用这一行。
  • @Paul 那是一个 XML prolog,它与 HTML 无关。


来源:https://www.codenong.com/8573335/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_10026.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?