I have some file called main.config which has:
{"name":"wtf","image":"main.PNG","desc":"This is about this that and that.","tags":{"php","js","html"}}
Now in php I am reading this file and getting its content like this:
$string = "";
$handle = fopen("main.config", "r");
while(!feof($handle)){
$string .= fgets($handle);
}
fclose($handle);
And now I have been trying to decode this but it always return either null
or string with additional ""
around.
"{"name":"wtf","image":"main.PNG","desc":"This is about this that and that.","tags":{"php","js","html"}}"
This is everything I tried:
json_decode( preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $string), true );
json_decode(preg_replace('/\s+/', '',$string), true);
json_decode(preg_replace('/\x{FEFF}/u', '', $string), true);
json_decode(str_replace('"', '"', $string));
utf8_encode($string);
stripslashes($string);
trim($string);
html_entity_decode($string);
json_decode(print_r($string, true), true);
But nothing seems to work, is it because I used some different file type or what could it be?