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];
}
You are replacing
$arrin every loop.$arr[] = $img;should work.Example: