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

  • SEARCH
  • Home
  • 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

Ask A Question

Stats

  • Questions 493k
  • Answers 493k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I made the following 2 edits: ofstream mann(file.c_str(), ios::app|ios::binary); while… May 16, 2026 at 10:47 am
  • Editorial Team
    Editorial Team added an answer GMail's SMTP requires encryption. Use: Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, "ssl"); May 16, 2026 at 10:47 am
  • Editorial Team
    Editorial Team added an answer How can you append an input type to a table… May 16, 2026 at 10:47 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I need to URLENCODE this: <?php echo 'chart.php?api_url=http://0.chart.apis.google.com/chart?'.$chart1title.$chart1type.$chart1size.$chart1barsize.$chart1gridlines.$chart1data.$chart1color.$chart1bgcolor.$chart1visibleaxis.$chart1axislabels.$chart1axisdatascale.$chart1axisranges.'alt=answeredcalls';?> And then decode it on the
I'm a bit worried if this function sends emails that can be recognized correctly
I have this code: import os path = os.getcwd() final = path +'\xulrunner.exe '
I'm trying to decide which datastructure to use to store key-value pairs when only
I need to tweak the web interface of an in-house print system, but it's
I need a client-server encryption solution for web transfer, (i.e. signed and encrypted client-side,
Here's what I need to do: Load 66px x 66px images into the table
I need to use a regex pattern , but what is the right php
I love the windows 7 sticky note app and need to write a quick
I need to know how does svcutil and Visual Studio decide which types can

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.