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

问题描述

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

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:

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

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()

Sanitize :: html()

EDIT:

h():调用 htmlspecialchars()

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


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

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

For discussion on differences, see: htmlentities vs htmlspecialchars

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

09-18 23:41