mb_convert_variables.php8
32 lines
| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | * This file is part of the Symfony package. |
| 5 | * |
| 6 | * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | * |
| 8 | * For the full copyright and license information, please view the LICENSE |
| 9 | * file that was distributed with this source code. |
| 10 | */ |
| 11 | |
| 12 | use Symfony\Polyfill\Mbstring as p; |
| 13 | |
| 14 | if (!function_exists('mb_convert_variables')) { |
| 15 | /** |
| 16 | * Convert character code in variable(s) |
| 17 | */ |
| 18 | function mb_convert_variables($to_encoding, $from_encoding, &$var, &...$vars) |
| 19 | { |
| 20 | $vars = [&$var, ...$vars]; |
| 21 | |
| 22 | $ok = true; |
| 23 | array_walk_recursive($vars, function (&$v) use (&$ok, $to_encoding, $from_encoding) { |
| 24 | if (false === $v = p\Mbstring::mb_convert_encoding($v, $to_encoding, $from_encoding)) { |
| 25 | $ok = false; |
| 26 | } |
| 27 | }); |
| 28 | |
| 29 | return $ok ? $from_encoding : false; |
| 30 | } |
| 31 | } |
| 32 |