Hi, I need to decode and specifically target the first url only in this array:
[{
"longDateTime":"3:00pm Saturday 21 August 2010",
"shortDateTime":"3:00pm Sat",
"url":"\/Pics\/ob\/7d778-127a9294cec0-12a929779a2b.Img.jpeg"
},{
"longDateTime":"2:00pm Saturday 21 August 2010",
"shortDateTime":"2:00pm Sat",
"url":"\/Pics\/ob\/7d778-12a9275de040-12a92760c93c.Img.jpeg"
},{
"longDateTime":"1:00pm Saturday 21 August 2010",
"shortDateTime":"1:00pm Sat",
"url":"\/Pics\/ob\/7d778-12a79226f1c0-12a79229bb4c.Img.jpeg"
},{
"longDateTime":"12:00pm Saturday 21 August 2010",
"shortDateTime":"12:00pm Sat",
"url":"\/Pics\/ob\/7d778-12a917f00340-12a91f3437fd.Img.jpeg"
},{
"longDateTime":"11:00am Saturday 21 August 2010",
"shortDateTime":"11:00am Sat",
"url":"\/Pics\/ob\/7d778-12a91b914c70-172a91bf8987.Img.jpeg"
},{
"longDateTime":"10:00am Saturday 21 August 2010",
"shortDateTime":"10:00am Sat",
"url":"\/Pics\/ob\/7d778-12a918226470-12a91784f47a.Img.jpeg"
}
]
The script that I am using works to grab the last or maybe a random url but as I said I really need to get it to target the first url only - can someone please modify my script so that I can achieve this please.
<?php
$radar_dir='./radar/';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'http://somesite.com/public/test');
$fp = fopen($radar_dir.'test.txt', 'w');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_exec ($ch);
curl_close ($ch);
fclose($fp);
?>
<?php
{
$txt_file = $radar_dir.'test.txt';
if(file_exists($txt_file)==false)
$img = $error_img;
else
{
$handle = fopen($txt_file, 'r');
$obj = fread($handle,filesize($txt_file));
$array_of_objects = json_decode($obj);
$object = $array_of_objects[0];
$url = ($object->url);
$img = "http://somesite.com" . $url;
}
copy($img,$radar_dir.'test.png');
}
?>
I would really appreciate any help with this.