Jump to content

Invalid UTF-8 sequence in argument


s0c0

Recommended Posts

Hello,

 

I receive the following FATAL error:

json_encode() [<a href='function.json-encode'>function.json-encode</a>]: Invalid UTF-8 sequence in argument

 

Here is the code:

echo json_encode($cart->get_products());

 

get_products returns an array even if its just an empty array.

 

Does anyone have any experience with this or seen it before. Couldn't find any solutions through googling around and am wondering if I need pass the encoded data through something like http://www.php.net/manual/en/function.utf8-encode.php

 

Please advise.

Link to comment
https://forums.phpfreaks.com/topic/239669-invalid-utf-8-sequence-in-argument/
Share on other sites

Hello,

 

I've seen this error before when invalid utf-8 characters were being encoded.  So most likely whatever your function is returning has an invalid utf8 character in it. I resolved the issue by doing somthing like this to clean out the invalid characters:

 

<?php
$newstring = iconv('UTF-8', 'ISO-8859-1//IGNORE', $string);

 

Where the $string variable is the utf-8 string with the invalid character.  I'm not too sure if this is a valid solution to you, but it may be something to look into.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.