Forum Moderators: coopster
I'm trying to convert JSON data to XML data using PHP.
I wrote script that do it well, but it gives error when input JSON data has "wrong data".
The error is:
<br/>
<b>Warning</b>
: Invalid argument supplied for foreach() in
<b>/home/re/xmlDestinationsQuery.php</b>
on line
<b>91</b>
<br/>
You can see it in <snip>.
The raw JSON data for this XML data is
<snip>
I think the error occurs when PHP script meets this line from raw JSON data:
"The Hôtel de Ville (French for \\"City Hall\\"), Paris "
I wonder, how can I parse those \\" symbols in PHP? I tried str_replace, but it didn't work for me. I've tried to use htmlentities, but it gives more errors.
PHP code is:
$panoFile = "http://www.example.com/map/get_panoramas.php?order=popularity&set= public&from=0&to=".$panoCount."&minx=".$lnglow."&miny=".$latlow."&maxx= ".$lnghigh."&maxy=".$lathigh."&size=small";
$file = fopen($panoFile, "r");
$panoQuery = stream_get_contents($file);
fclose($file);$panoArray = json_decode($panoQuery, true);
$panoArrayNext = $panoArray['photos'];// the line 91 which gives error is here:
foreach($panoArrayNext as $pano){echo '<pano ';
echo 'photo_id="'.$pano['photo_id'].'" ';
echo 'photo_title="'.$pano['photo_title'].'" ';
echo 'photo_url="'.$pano['photo_url'].'" ';
echo 'photo_file_url="'.$pano['photo_file_url'].'" ';
echo 'lng="'.$pano['longitude'].'" ';
echo 'lat="'.$pano['latitude'].'" ';
echo 'width="'.$pano['height'].'" ';
echo 'upload_date="'.$pano['upload_date'].'" ';
echo 'owner_id="'.$pano['owner_id'].'" ';
echo 'owner_name="'.$pano['owner_name'].'" ';
echo 'owner_url="'.$pano['owner_url'].'" ';echo '/>';
}
[edited by: dreamcatcher at 6:30 pm (utc) on Aug. 22, 2007]
[edit reason] no urls as per T.O.S [webmasterworld.com].Thanks [/edit]
$panoArrayNext = $panoArray['photos'];
echo '<pre>';
print_r($panoArrayNext);
echo '</pre>';
exit;
Without "header("Content-type: text/xml");" it gives:
[q]Notice: Undefined variable: panoArrayNext in /home/re/xmlDestinationsQuery1.php on line 91[/q]
You can check modified query (with <pre>....</pre) <snip>
[edited by: eelixduppy at 11:40 am (utc) on Aug. 23, 2007]
[edit reason] no personal urls, please [/edit]