Created
February 6, 2025 14:18
-
-
Save win3zz/8598d14b343cc37e7d488f4248a13f8a to your computer and use it in GitHub Desktop.
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 | |
echo myMessage("WELCOME", "win3zz", 0); | |
function myMessage() { | |
$messages = [ | |
"WELCOME" => "Welcome, %s! You have %d new messages.", | |
"ERROR" => "An error occurred: %s" | |
]; | |
$numargs = func_num_args(); | |
$args = func_get_args(); | |
$messagename = $args[0]; | |
if (@array_key_exists($messagename, $messages)) { $string_with_percents = $messages[$messagename]; } | |
else { return "MESSAGE NOT FOUND"; } | |
$sprintf_argument = "\$translated_string = sprintf(\$string_with_percents"; | |
for ($i=1; $i<$numargs; $i++) { | |
$sprintf_argument .= ", @htmlentities(\$args[$i], ENT_QUOTES)"; | |
} | |
$sprintf_argument .= ");"; | |
eval($sprintf_argument); | |
return $translated_string; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment