1
$files = array();
$dir = opendir(dirname(realpath(__FILE__)).'/files/'.$fil_fi_row['file_name'].'/');
while ($file = readdir($dir)) {
    if ($file == '.' || $file == '..') {
        continue;
    }
    $allfiles[] = $file;
}

$total_arr=array_merge((array)$id,(array)$files);
sort($total_arr);
foreach($total_arr as $key=>$file){
    if($key != count($total_arr)-1)
        $array[‘Files’][] = array(                                         
            ‘files’ => $file,
            ‘id’ => $id,
        );
    }
}   
echo  json_encode($array, JSON_UNESCAPED_UNICODE);

I tried JSON_UNESCAPED_UNICODE but does not work; ERROR

Notice: Use of undefined constant JSON_UNESCAPED_UNICODE - assumed 'JSON_UNESCAPED_UNICODE' in /home/...

Warning: json_encode() expects parameter 2 to be long, string given in /home/..

When I use

echo  json_encode($array);

the Arabic file name appears as:

8508_\u0645\u0635\u0631 \u0627\u0643\u0631\u0645 20150908 
OsamahM
  • 337
  • 1
  • 2
  • 16
  • `JSON_UNESCAPED_UNICODE` was introduced with PHP 5.4 – mario May 08 '16 at 20:14
  • 1
    show the `$array` contents – RomanPerekhrest May 08 '16 at 20:14
  • RomanPerekhrest see the code now ...thanks – OsamahM May 08 '16 at 20:20
  • I fixed some wrong quotes in the second line of your code; I assume you have that right in your own code (otherwise it would not work at all). – trincot May 08 '16 at 20:29
  • When you ask a question about an error, **ALWAYS** post the error log. To enable error reporting to your php code, append `error_reporting(E_ALL); ini_set('display_errors', '1');` at the top of your script, what does it return ? If there's an error, you won't see a "***blank page***" – Pedro Lobito May 08 '16 at 20:34
  • 1
    could you provide the output when you do `var_export ($array);` just before the `json_encode()`? The Arabic file name would probably be correct ***IF*** there were backslashes before each `u`. Did you use `stripslashes()` anywhere? – trincot May 08 '16 at 20:34
  • trincot i do not use stripslashes() arabic file name 8508_\u0645\u0635\u0631 \u0627\u0643\u0631\u0645 20150908 – OsamahM May 08 '16 at 20:47
  • Pedro Lobito .. error : Notice: Use of undefined constant JSON_UNESCAPED_UNICODE - assumed 'JSON_UNESCAPED_UNICODE' in dir ... Warning: json_encode() expects parameter 2 to be long, string given in – OsamahM May 08 '16 at 20:51
  • @user6107006 you php version is < PHP5.4.0 – Pedro Lobito May 08 '16 at 21:01
  • take a look at this answer http://stackoverflow.com/a/6771980/797495 or this http://stackoverflow.com/a/16898723/797495 – Pedro Lobito May 08 '16 at 21:03
  • oh >> PHP Version 5.3.29 – OsamahM May 08 '16 at 21:03
  • Possible duplicate of [undefined constant JSON\_UNESCAPED\_UNICODE in codeigniter](http://stackoverflow.com/questions/24925023/undefined-constant-json-unescaped-unicode-in-codeigniter) – the_nuts May 08 '16 at 21:05

2 Answers2

0

try this (PHP5.4.0+)

json_encode($result, JSON_UNESCAPED_UNICODE);
Oussema Aroua
  • 5,225
  • 1
  • 24
  • 44
0

You Need To Add The following Code

header('Content-Type: applcation/json; charset = utf-8');
mysqli_set_charset($conn,"utf8");

worked for me

Muhammad Aqeel
  • 81
  • 1
  • 11