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 7043227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:15:48+00:00 2026-05-28T02:15:48+00:00

I am parsing data from a website via xml that always changes so I

  • 0

I am parsing data from a website via xml that always changes so I do not know what data to search for, just the location. I get the data by calling upon the specific class for the data needed. Within this class that is retrieved, there are only certain things I need retrieved. So for example, I retrieve the class .candy. Now .candy corresponds to different parts on the website so let us say that candy retrieves “Cookies Chocolate gummy bear”. I only want “chocolate”.

My idea was to put everything into an array an array and then access it. Assume the array is called test, then I would want to access “chocolate” by $test[1];

It is not working for me (says array is out of bounds whenever I put a number bigger than 0) and I was wondering if anyone knows where my mistake is within my code? Please note that the above was purely an example for better understanding and not the actually data I need.

Thank you

function getData($html)                             
{                               
    @$doc=new DOMDocument();
    @$doc->loadHTML($html);
    $xml=simplexml_import_dom($doc); // just to make xpath more simple
    //$images=$xml->xpath('//[]');
    $info=$xml->xpath('//*[@class="date"]'); 
    $arr= array();

    foreach ($info as $img) {                                 
        $arr= array($img);          
    }
    return $arr[3];
}
  • 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-28T02:15:49+00:00Added an answer on May 28, 2026 at 2:15 am

    You are replacing $arr in every loop. $arr[] = $img; should work.

    Example:

    function getData($html)
    {       
        @$doc = new DOMDocument();
        @$doc->loadHTML($html);
        $xml = simplexml_import_dom($doc);
        $info = $xml->xpath('//*[@class="date"]'); 
        $arr = array();
    
        foreach ($info as $img)
        {
            $arr[] = $img;
        }
    
        return $arr[3];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I read from the jQuery website, that get() loads data from the server using
i'm still transitioning from as2 to as3, i'm having trouble with parsing XML data
I am parsing XML returned from a website but sadly it is slightly malformed.
I've got a website that I'd like to pull data from and it's really
I'm building a server in Node.js that receives data from Javascript on a website.
I need to get Json data from a C# web service. I know there
I get an XML from website into a string strXML. Then I create an
I'm parsing data from this RSS feed: http://rss.accuweather.com/rss/liveweather_rss.asp?metric=1&locCode=SAM|AR|AR005|MONTE%20MAIZ , The data there updates once
I'm having difficulty parsing some JSON data returned from my server using jQuery.ajax() To
I'm reading XML data from the HttpServletRequest in my servlets doPost() and passing the

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.