JSON and utf-8 problems when inserting data in BD from php

0

I am currently having a problem in decoding PHP characters, I am calling an API using a file_get_contents () and then calling with a variable:

            $jsondata = file_get_contents(URL DEL API);
            $data = json_decode($jsondata, true, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);

But when doing the decode all the characters that have tilde have a strange character ... already try making encode and later a decode with utf8 (this had already happened to me in other php without the file_get_contents ()):

            $data = json_encode($jsondata, true, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);    
            $data2 = utf8_decode($data);

And I get this error:

 Warning:  Illegal string offset 'actions' in /var/www/html/psu/public/json/zjson.php on line 30
 Warning:  Invalid argument supplied for foreach() in /var/www/html/psu/public/json/zjson.php on line 30

Is there any way to convert this data to utf-8 and save it in that format in my database?

    
asked by Samuel 09.11.2018 в 13:41
source

1 answer

0

After so much searching and searching I found the solution, with this I force the coding in utf-8 after the query:

$result = mysql_set_charset('utf8', $conexion);
$result = mysql_query("SET NAMES utf-8");
    
answered by 09.11.2018 / 19:54
source