Your probleme
See :
die(var_dump(file_get_contents ("http://www.klh-dev.com/adom/alert/alerts.json")));
The web page alerts.json is not properly encoded. See output :
string '��{� � � �"�i�d�"� �:� �"�1�4�0�5�2�5�4�5�8�0�5�6�8�"�,� �
�"�t�i�t�l�e�"� �:� �"������ ������ ������ ������ �"�,�
� �"�d�a�t�a�"� �:� �[� � �"����� ���� �2�2�8�"� � �]� � �}� � �' (length=206)
Solution
You must to clean your string. Remove null character '\0' after all character except with arabic character, and 'ÿþ' on the beginning of string (it's UTF-16 mark).
iconv function see :
Convert UTF-16LE to UTF-8 in php
UTF-16 : PHP File Opening Encoding Problem?
<?php
$web = file_get_contents ("http://www.klh-dev.com/adom/alert/alerts.json");
$str_datakey = join("\0", preg_split("//", '"data" : ['));
$pos_datakey = strrpos($web, $str_datakey) + strlen($str_datakey);
preg_match('#"\0t\0i\0t\0l\0e\0"\0.+"\0(.*)"#', $web, $match);
preg_match('#"\0(.*)"#', $web, $match2, null, $pos_datakey);
// Replace title to replace null bit except title (with arabic char)
$title = $match[1];
$web = str_replace($title, "[HorsSujet]", $web);
// Replace string data to replace null bit except string data (with arabic char)
if (!empty($match2)) {
$match2 = array_slice($match2, 1);
$web = str_replace($match2, "[HorsSujet_data]", $web);
}
$web = str_replace(array('ÿþ', "\0"), "", $web);
$title = iconv("UTF-16LE", "UTF-8", $title);
for ($i = 0; $i < count($match2); $i++) {
$match2[$i] = iconv("UTF-16LE", "UTF-8", $match2[$i]);
}
$web = str_replace("[HorsSujet]", $title, $web);
if (!empty($match2)) {
$web = str_replace(array("[HorsSujet_data]"), $match2, $web);
}
$json = $web;
$array = json_decode($web);
var_dump($match, $match2, $web, $array);
See output :
http://jsbin.com/dumon/1 (<= with highlight).
array (size=2)
0 => string '"�t�i�t�l�e�"� �:� �"������ ������ ������ ������ �"' (length=71)
1 => string '����� ������ ������ ������ �' (length=48)
array (size=1)
0 => string 'עוטף עזה 228' (length=19)
string '{
"id" : "1405254580568",
"title" : "פיקוד העורף התרעה במרחב ",
"data" : [
"עוטף עזה 228"
]
}
' (length=129)
object(stdClass)[1]
public 'id' => string '1405254580568' (length=13)
public 'title' => string 'פיקוד העורף התרעה במרחב ' (length=44)
public 'data' =>
array (size=1)
0 => string 'עוטף עזה 228' (length=19)
Example : https://eval.in/172185