Json.php 1022 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace ModulesGarden\Servers\ProxmoxVps\Core\Helper\Converter;
  3. class Json
  4. {
  5. public static function encodeUTF8($array)
  6. {
  7. array_walk_recursive($array, function(&$item, $key)
  8. {
  9. if (is_array($item) || is_object($item))
  10. {
  11. foreach ($item as &$param)
  12. {
  13. if (is_array($param) || is_object($param))
  14. {
  15. $param = self::encodeUTF8($param);
  16. }
  17. else
  18. {
  19. if (!mb_detect_encoding($param, 'utf-8', true))
  20. {
  21. $param = utf8_encode($param);
  22. }
  23. }
  24. }
  25. }
  26. else
  27. {
  28. if (!mb_detect_encoding($item, 'utf-8', true))
  29. {
  30. $item = utf8_encode($item);
  31. }
  32. }
  33. });
  34. return $array;
  35. }
  36. }