mb_convert_variables.php8 831 B

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