Laravel malformed character UTF-8
You are using strings that are coming from the filesystem filenames. Such strings are typically not in UTF-8 and use the ISO-8859-1 (usually). Coincidentally this is the required input encoding which utf8_encode
requires to work.
$drives = ['M1', 'M2', 'M3', 'M4'];
$movies = [];
foreach ($drives as $drive) {
$disk = Storage::disk($drive);
foreach ($disk -> directories() as $movie) {
$movies[] = utf8_encode($movie);
}
}
return response()->json($movies, 200, ['Content-type'=> 'application/json; charset=utf-8'], JSON_UNESCAPED_UNICODE);
However, if you do wish to convert to UTF-8 from another (known) encoding you need to use mb_convert_encoding
. Overall be aware that setting the HTTP response encoding to UTF-8 will not automatically convert any character encodings. You have to do that manually.
Laravel malformed UTF-8 characters, possibly incorrectly encoded using image intervention
The problem was this line, I was saving the actual image object in the db.
$product->image = \Image::make($request->image)->save(public_path('img/').$fileName);
I changed it into
$imageData = $request->image;
$fileName = time().'.'. explode('/', explode(':', substr($imageData, 0, strpos($imageData, ';'))) [1])[1];
\Image::make($request->image)->save(public_path('img/').$fileName);
$product->image = $fileName;
$product->save();;
possibly incorrectly encoded,Malformed UTF-8 characters
In my laravel query i am use a following code so it will give a this type of error...
Malformed UTF-8 characters, possibly incorrectly encoded
$BvoData = DB::table('test1')->select('test1.*')
->where("test1.Id", "".$id."")
->first();
$BvoData->temp1 = DB::table('temp1')->where('tmpdata', $BvoData->tmpdata)->get();
$BvoData->temp2 = DB::table('temp2')->where('Id', $id)->get();
return response()->json($BvoData);
but i will solve this error by doing following code...
$BvoData = DB::table('test1')->select('test1.*')
->where("test1.Id", "".$id."")
->first();
$BvoData = (array) $BvoData;
$BvoData->temp1 = DB::table('temp1')->where('tmpdata', $BvoData->tmpdata)->get();
$BvoData["temp1"] = json_decode(json_encode($BvoData["temp1"]), True);
$BvoData->temp2 = DB::table('temp2')->where('Id', $id)->get();
$BvoData["temp2"] = json_decode(json_encode($BvoData["temp2"]), True);
return response()->json($BvoData);
by using json_decode and json_encode i solve my problem...
Related Topics
Simple PHP Form: Attachment to Email (Code Golf)
Pdo Try-Catch Usage in Functions
What's the Most Efficient Test of Whether a PHP String Ends with Another String
Use One Laravel Migrations Table Per Database
Make Switch Use === Comparison Not == Comparison in PHP
How to Redirect to Another Page Using PHP
What's the Difference Between Array_Merge and Array + Array
PHP Cli Getting Input from User and Then Dumping into Variable Possible
Codeigniter Activerecord, Retrieve Last Insert Id
Laravel Mail: Pass String Instead of View
Non-Static Method ..... Should Not Be Called Statically
Detecting Ajax in PHP and Making Sure Request Was from My Own Website
How to Set Cron Job Url for Codeigniter