2

That error occurs in my Laravel application in some Ajax requests, when the page is reloaded. Some requests fail and return the following response:

exception: "InvalidArgumentException"
file: "C:\wamp64\www\<my app directory>\vendor\laravel\framework\src\Illuminate\Http\JsonResponse.php"
line: 75
message: "Malformed UTF-8 characters, possibly incorrectly encoded"

What causes that error? How to fix it?

Luan Silveira
  • 21
  • 1
  • 1
  • 4
  • We will need more information such as the ajax call code and if possible dump the response you are returning from it. dd($response): – Michael Mano Feb 06 '19 at 10:49
  • 1
    Also get off windows for development. Jus saying it will make your life a lot easier haha. – Michael Mano Feb 06 '19 at 10:52
  • https://stackoverflow.com/questions/31115982/malformed-utf-8-characters-possibly-incorrectly-encoded-in-laravel – mujuonly Feb 06 '19 at 10:53

1 Answers1

13

This error is usually caused by the use of the standard string library instead of mbstring on utf8 characters.

Make sure you aren't using any str functions on any of the values prior to returning the JSON response. One time I hit this, I found a mutator in a model using substr instead of mb_substr.

Devon Bessemer
  • 34,461
  • 9
  • 69
  • 95