php - Laravel malformed character UTF-8 -


when try grab list of directories , use list in json response, error response has malformed utf-8 characters. know have letters "Æ Ø Å" in directories. when use dd($directories) can see "b" infront of every directory contains "Æ Ø Å" letter (as can see in photo).

i tried use this, not work either. return response() -> json($movies, 200, ['content-type'=> 'application/json; charset=utf-8'], json_unescaped_unicode);

edit: code have now.

$drives = ['m1', 'm2', 'm3', 'm4']; $movies =[];  foreach ($drives $drive) {      $disk = storage::disk($drive);     foreach ($disk -> directories() $movie) {         $movies[] = $movie;     }  }  return response() -> json($movies, 200, ['content-type'=> 'application/json; charset=utf-8'], json_unescaped_unicode); 

enter image description here

you using strings coming filesystem filenames. such strings typcally not in utf-8 , use iso-8859-1 (usually). coincidentally required input encoding utf8_encode requires work.

$drives = ['m1', 'm2', 'm3', 'm4']; $movies =[];  foreach ($drives $drive) {      $disk = storage::disk($drive);     foreach ($disk -> directories() $movie) {         $movies[] = utf8_encode($movie);     }  }  return response() -> json($movies, 200, ['content-type'=> 'application/json; charset=utf-8'], json_unescaped_unicode); 

however, if wish convert utf-8 (known) encoding need use mb_convert_encoding($str,"utf-8",$from_encoding). overall aware setting http response encoding utf-8 not automatically convert character encodings. have manually.


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -