Skip to content

Instantly share code, notes, and snippets.

@win3zz
Created February 6, 2025 14:18
Show Gist options
  • Save win3zz/8598d14b343cc37e7d488f4248a13f8a to your computer and use it in GitHub Desktop.
Save win3zz/8598d14b343cc37e7d488f4248a13f8a to your computer and use it in GitHub Desktop.
<?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