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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.