Last active
October 9, 2015 11:47
-
-
Save mamchenkov/3498902 to your computer and use it in GitHub Desktop.
Nested sprintf() / vsprintf with gettext example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Example of sprintf()/vsprintf() with gettext | |
*/ | |
/** | |
* String translation | |
* | |
* @param string $param String to translate | |
* @return string Translated string (surrounded by square brackets for visibility) | |
*/ | |
function __($param) { | |
return '[' . $param . ']'; | |
} | |
// Substring | |
$googleLink = sprintf('<a href="%s">%s</a>', 'http://www.google.com', __('Google')); | |
// Main string formatting with variable parameters count | |
$params = array('Leonid', $googleLink); | |
$message = vsprintf(__("Welcome, %s! Click on %s to finish."), $params); | |
echo $message; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment