欧元符号显示为\ u00e2 \ u00ac \ u00ac和â€

I know there are a lot of topics out there concerning this problem, but I've spend the last hours trying various approaches an I'm nowhere close to the solution. So here it goes ...

This is my jquery:

$.post('inc/app_json_f.php',{params:priv_params}, function (data) {
  console.log(data);
  // displays: \u00e2\u0082\u00ac instead of €
  data = JSON.parse(data);
  console.log(data);
  // displays: â¬â¬ instead of €
}

This is my php (the app_json_f.php page):

$qry = 'select ... from ... where ...';
$data = $db->do_select($qry);

echo json_encode(f_utf8_json($data));

The f_utf8_json function will check the $data and convert every value with utf8_encode().

At this moment, the echo json_encode(...) will display the following in the console:

\u00e2\u0082\u00ac

Whereas I would like to see the € sign.

The data comes from a MySQL database which has collation utf8_general_ci. PHP's charset is UTF-8.

Any suggestions?

By removing the f_utf8_json function (the one that converts the values to utf8 with utf8_encode()), everything works ok. Strange, because I added this function earlier in the project because it was necessary to get the right results. I have to double check, but possibly another database setting was the cause of this.

Problem solved.

for send file using curl you need to use this working code.

if(!empty($postfields['image'])){
$file_name_with_full_path = $postfields['image'];
  if (function_exists('curl_file_create')) { // php 5.6+
    $cFile = curl_file_create($file_name_with_full_path);
  } else { // 
    $cFile = '@' . realpath($file_name_with_full_path);
  }
  $postfields['fileToUpload'] =  $cFile;

}

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
$result=curl_exec ($ch);
curl_close ($ch);

User curl_file_create

When using json_encode(), include JSON_UNESCAPED_UNICODE as the second argument so that you don't get \u0123 type codes, but instead get UTF-8.

The hex for UTF-8 encoding of is E2ACE2AC. (Ditto for MySQL's utf8 and utf8mb4.)

If you get €, then you have "Mojibake".

If you take UNHEX(E2ACE2AC) and treat it as any of cp1250, cp1256, cp1257, latin1, latin5, latin7, you get â¬â¬. It sounds like you are compounding errors to get there.

See the "best practices" and other debugging tips here: Trouble with utf8 characters; what I see is not what I stored