Вопрос

 $response="بسم الله الرحمن الرحيم";       
 $string='{

    "something": "'.$response.'"
}';

Please give me a solution to json_decode above string. When I try json_decode($string, true, JSON_UNESCAPED_UNICODE); result is null

Это было полезно?

Решение

Most probably json_decode have problem with arabic charactor. The arabic text should convert to utf-8.if after decode also the arabic text coming properly hope you will get the result.

@header('Content-Type: text/html; charset=utf-8');


$response="بسم الله الرحمن الرحيم";  

$response= iconv('windows-1256', 'utf-8', ($response)); 
$string='{

"something": "'.$response.'"
}';

echo "Before Decode :";
var_dump($string);

echo "After Decode :";
$json=json_decode($string);
var_dump($json);

Другие советы

You will have to change the charset of your DBMS to one that suits your needs.

Assuming your are using MySQL and PHPMyAdmin, you have to go to your PHPMyAdmin page and choose an appropriate charset. The default is, as far as I remember, UTF-8.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top