tags:

views:

297

answers:

9

Hi, I and lately I'm seeing h() and e() functions in php... I have googled them, but they are so short that results doesn't give any idea of what they are. I got results like exponential, or math related functions.

for example:

<td><?php echo h($room['Room']['message']) ?></td>

Does any one has 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:

<?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 ;(

+6  A: 

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.

Nothing here:

http://us3.php.net/manual/en/function.h.php

http://us3.php.net/manual/en/function.e.php

Mr-sk
+5  A: 

Likely the framework you're using is doing some escaping and has defined some short hands for htmlentities and htmlspecialchars or equivalents.

I'd do a search on whatever framework you're using for "function h("

Allain Lalonde
+4  A: 

Most likely, they are dummy functions someone introduced for the sake of brevity. The h(), for example, looks like an alias for 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".

Seva Alekseyev
+6  A: 

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.

GSto
+3  A: 

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.

ceejayoz
`e()` may also be `urlencode`. Personally I use `h()` to do `echo(htmlspecialchars())` to cut down on templating verbosity.
bobince
A: 

If you are using a decent editor press ctrl and click on the function. It should take you to the function's declaration.

AntonioCS
These would have to be actual stock PHP functions for that to work.
ceejayoz
Not really. I know in Netbeans you can go to the declaration so long as the file where it is declared is in your include path. It's a good way to see what's happening.
Blair McMillan
+3  A: 

Google code search might help:

http://www.google.com/codesearch?hl=en&amp;lr=&amp;q=\se\(+\sh\(++lang:php&amp;sbtn=Search

It looks like it might be CakePHP

Tom Haigh
thanks, for this... It is a big help, and I am getting closer ;)
nacho4d
+6  A: 

As several readers have said, these are CakePHP-specific short-cuts. You can find them in the API docs at: api.cakephp.org/file/cake/basics.php

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

Zoltan
+1 for providing an actual link, unlike all the other answers that either say what the functions *aren't* a member of, or surmise that they're CakePHP without committing to that as the answer.
Rob Kennedy
A: 

http://book.cakephp.org/view/121/Global-Functions these are shortcut functions in cakePHP

Many of them are deprecated in 1.3 so beware of using them yourself

Sam D