I've a script in PHP that reads from a table in DDBB, set a JSON and send it by cURL but the endpoint receive characters like accents wrong (acutes).
1) Firstly, i connect to the bbdd and set the charset:
$conn=mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME) or die("Error " . mysqli_error($con));
mysqli_set_charset($conn,"utf8mb4");
The database collation is utf8mb4_unicode_ci
, I can't change that.
2) I build the array with the info:
$arr_json = array();
$array_json['key'] = htmlentities("Más");
[...]
3) Once is settled, create the JSON from the array:
$arr_json = json_encode($arr_json,JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
4) Finally, i send the info:
curl_setopt_array($curl, array(
CURLOPT_URL => URL,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $arr_json,
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"content-type: application/json",
),
));
I receive a 200 code, but the endoint of the API always receive wrong input, for example a previous value of:
'Más'
It would be:
'Más'
The PHP script file is UTF-8, and the info in database is correctly stored. Any ideas?