note 109051 deleted from function.gettext by danbrown
| From: | danbrown@php.net | Date: | Sat, 16 Jun 2012 13:11:53 +0000 |
| Subject: | note 109051 deleted from function.gettext by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-188642@lists.php.net to get a copy of this message | ||
Note Submitter: ddpp89 at hotmail dot com
----
A bit easy version of the code from Anonymous. Giving an associative array to the function, you can
see more easily what value is linked to what "variable".
Code:
function __($text, array $vars = array()) {
$search = array();
$replace = array();
foreach ($vars as $key => $value) {
$search[] = $key;
$replace[] = $value;
}
return str_replace($search, $replace, _($text));
}
How to use:
__('I have #NUMPOSTS# posts in my database! And #NUMUSERS# users.',
array('#NUMPOSTS#' => $numPosts, '#NUMUSERS# => $numUsers));
Thank you Anonymous :)