Created
January 11, 2022 13:57
-
-
Save sebastianbergmann/e3a0bc5f821169edb4fd23eda7d0e295 to your computer and use it in GitHub Desktop.
This file contains 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 declare(strict_types=1); | |
function mb_sprintf($format, ...$args): string | |
{ | |
$params = $args; | |
return sprintf( | |
preg_replace_callback( | |
'/(?<=%|%-)\d+(?=s)/', | |
static function ($length) use (&$params) { | |
$value = array_shift($params); | |
return strlen($value) - mb_strlen($value) + $length[0]; | |
}, | |
$format | |
), | |
...$args | |
); | |
} | |
function mb_printf($format, ...$args): void | |
{ | |
print mb_sprintf($format, ...$args); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment