php e() and h() functions?

Viewed 44751

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:

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

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

13 Answers

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)

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

edit: e() is deprecated in 1.3 and no longer available in 2.0 see here

It looks like it might be CakePHP.

See e()

e (mixed $data)

Convenience wrapper for echo().

This has been Deprecated and will be removed in 2.0 version. Use echo() instead.

See h()

h (string $text, string $charset = null)

Convenience wrapper for htmlspecialchars().

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".

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

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.

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.

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

Related