Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1017929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:46:49+00:00 2026-05-16T10:46:49+00:00

I need to decode and specifically target the first url only in this array:

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T10:46:49+00:00Added an answer on May 16, 2026 at 10:46 am

    Well, here is proof that your code, as is, displays the correct url.

    Just to be clear, the output is /Pics/ob/7d778-127a9294cec0-12a929779a2b.Img.jpeg (the 1st url) and not, /Pics/ob/7d778-12a918226470-12a91784f47a.Img.jpeg (the last url).

    However, I would just use $array_of_objects[0]->url; directly.

    So, your code works fine, but your decode is a little over complicated. Replace

    $array_of_objects = json_decode($obj);
    $object = $array_of_objects[0];
    $url = ($object->url);
    

    With:

    $array_of_objects = json_decode($obj);
    $url = $array_of_objects[0]->url;
    

    What is more important, is that I would test that your copy() actually works, using something like:

    if ( !copy($img, $radar_dir.'test.png') ) 
    {
        echo "failed to copy $img...\n";
    }
    

    At this point it seems that $img is a url of a jpeg, and you’re copying it to .../test.png, fwiw.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.