php e() 和 h() 函数?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2043072/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
php e() and h() functions?
提问by nacho4d
I and lately I'm seeing h()and e()functions in PHP. I have googled them, but they are so short that results don't give any idea of what they are. I got results like exponential or math related functions. For example:
我和最近我在 PHP 中看到h()和e()运行。我用谷歌搜索过它们,但它们太短了,结果不知道它们是什么。我得到了指数或数学相关函数之类的结果。例如:
<td><?php echo h($room['Room']['message']) ?></td>
Does anyone have an idea? or maybe they are not called functions? (I think I read about that very long ago, but I can remember its real name)
有没有人有想法?或者也许它们不被称为函数?(我想我很久以前就读过,但我记得它的真名)
ADDED:
添加:
Thanks, for the replies. I am using CakePHP and also found an e()example:
谢谢,回复。我正在使用 CakePHP,还找到了一个e()例子:
<?php e($time->niceShort($question['Question'] ['created'])) ?>
If they were escaping somehow strings I think it would make sense, since I always see them right next the "echo"
如果他们以某种方式转义字符串,我认为这是有道理的,因为我总是在“回声”旁边看到它们
I still don't know what they are ;(
我仍然不知道它们是什么;(
采纳答案by Tom Haigh
It looks like it might be CakePHP.
看起来它可能是 CakePHP。
See e()
见e()
e (mixed $data)
Convenience wrapper for echo().
This has been Deprecated and will be removed in 2.0 version. Use echo() instead.
e(混合$数据)
echo() 的便利包装器。
这已被弃用,将在 2.0 版本中删除。请改用 echo()。
See h()
见h()
h (string $text, string $charset = null)
Convenience wrapper for htmlspecialchars().
h (字符串 $text, 字符串 $charset = null)
htmlspecialchars() 的便利包装器。
回答by Zoltan
As several readers have said, these are CakePHP-specific short-cuts. You can find them in the API docs at: here(for CakePHP 2.x)
正如一些读者所说,这些是特定于 CakePHP 的捷径。您可以在 API 文档中找到它们:here(对于 CakePHP 2.x)
I think I read that some of these are going to be removed in 1.3, personally I never used e() as typing echo really doesn't take that much longer :)
我想我读到其中一些将在 1.3 中删除,我个人从未使用过 e() 因为输入 echo 真的不需要那么长时间:)
edit: e() is deprecated in 1.3 and no longer available in 2.0 see here
编辑:e() 在 1.3 中已弃用,在 2.0 中不再可用,请参见此处
回答by Seva Alekseyev
Most likely, they are dummy functions someone introduced for the sake of brevity. The h(), for example, looks like an alias for htmlspecialchars():
最有可能的是,它们是有人为了简洁而引入的虚拟函数。例如,h() 看起来像 htmlspecialchars() 的别名:
function h($s)
{
return htmlspecialchars($s);
}
So look for them in the include files. Espec. the ones with names likes "util.php" or "lib.php".
所以在包含文件中寻找它们。特别是 名字像“util.php”或“lib.php”的那些。
回答by Allain Lalonde
Likely the framework you're using is doing some escaping and has defined some short hands for htmlentitiesand htmlspecialcharsor equivalents.
可能您使用的框架正在做一些转义,并为htmlentities和htmlspecialchars或等价物定义了一些简写。
I'd do a search on whatever framework you're using for "function h("
我会搜索您用于“function h(”的任何框架
回答by mr-sk
They are probably functions defined and implemented by the group's code that you're looking at. I'm not aware of any e/h functions in the PHP language.
它们可能是由您正在查看的组代码定义和实现的功能。我不知道 PHP 语言中的任何 e/h 函数。
Nothing here:
这里没有什么:
http://us3.php.net/manual/en/function.h.php
http://us3.php.net/manual/en/function.h.php
回答by GSto
There aren't any functions in PHP called h() and e(). They must be declared in the project you are working on. search for them and find out what they do.
PHP 中没有任何称为 h() 和 e() 的函数。它们必须在您正在处理的项目中声明。搜索他们并了解他们的工作。
回答by ceejayoz
I'd guess that h()escapes user-submitted data for safe output, and e()escapes for database insertion. Whatever the functionality, these are not stock PHP functions.
我猜想这会h()转义用户提交的数据以进行安全输出,并e()转义数据库插入。无论功能如何,这些都不是 PHP 的常用函数。
回答by newshorts
It's CakePHP.
这是 CakePHP。
echo h('some stuff')
Is just htmlspecialchar()ing the stuff.
只是htmlspecialchar()在看东西。
回答by Hyman1987
In CakePHP h() is: Convenience wrapper for htmlspecialchars()
在 CakePHP 中 h() 是: htmlspecialchars() 的便利包装器
For more information about Global constants and functions in CakePHP view this link
有关 CakePHP 中全局常量和函数的更多信息,请查看此链接
http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html
http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html
回答by AntonioCS
If you are using a decent editor press ctrl and click on the function. It should take you to the function's declaration.
如果您使用的是不错的编辑器,请按 ctrl 并单击该功能。它应该带你到函数的声明。

