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);
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
Post a Comment