CakePHP:h()vs. Sanitize :: html() [英] CakePHP: h() vs. Sanitize::html()

查看:177
本文介绍了CakePHP:h()vs. Sanitize :: html()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CakePHP有一个全局函数,名为 h 。这是一个方便的方法 htmlspecialchars 。 CakePHP也有一个实用程序名为 Sanitize ,其中有一个方法 html 。以下是其说明的一部分:

CakePHP has a global function called h. It's a convenience method for htmlspecialchars. CakePHP also has a utility called Sanitize, which has a method called html. Here is part of its description:


此方法准备用户提交的数据以在HTML中显示。如果您不希望用户能够打破您的
布局或在HTML页面中插入图片或脚本,那么
特别有用。

This method prepares user-submitted data for display inside HTML. This is especially useful if you don’t want users to be able to break your layouts or insert images or scripts inside of your HTML pages.

什么时候应该使用?是否比另一个好?

When should each be used? Is one better than the other?

推荐答案

Sanitize :: html()更通用:它允许您完全剥离HTML(通过 remove 选项),并允许您指定它处理引号的方式。

Sanitize::html() is more versatile: it lets you strip the HTML completely (via remove option), and lets you specify the how it handles quoting.

查看源代码:

h() http://api.cakephp.org/2.3/source-function-h.html#160-199

Sanitize :: html() http://api.cakephp.org/2.3/source-class-Sanitize.html#83-122

EDIT:

h():调用 htmlspecialchars()

Sanitize :: html():调用 htmlentities()


h(): calls htmlspecialchars()
Sanitize::html(): calls htmlentities()

有关差异的讨论,请参阅: htmlentities vs htmlspecialchars

For discussion on differences, see: htmlentities vs htmlspecialchars

这篇关于CakePHP:h()vs. Sanitize :: html()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆