Convert arrays into UTF-8 ? PHP JSON

前端 未结 7 1793
盖世英雄少女心
盖世英雄少女心 2021-01-03 01:56

i have multidimensional arrays generated by PHP with data from database ,but i have chars like \"č ć š đ ž\" and when i try to output that in json he just returns null , i d

相关标签:
7条回答
  • 2021-01-03 02:38

    Try this PHP function where you simply pass in the array you wish encoded.

    function convertArrayKeysToUtf8(array $array) { 
    $convertedArray = array(); 
    foreach($array as $key => $value) { 
      if(!mb_check_encoding($key, 'UTF-8')) $key = utf8_encode($key); 
      if(is_array($value)) $value = $this->convertArrayKeysToUtf8($value); 
    
      $convertedArray[$key] = $value; 
    } 
    return $convertedArray; 
      } 
    

    P.s check out php.net for other utf-8 encoding method ideas, but this has worked for me in the past.

    0 讨论(0)
提交回复
热议问题