I'm having trouble getting this to work. I'm scraping a website using a xpath selector and this returns 38 results which are added to the array $list. Now the first 5 results and the last 3 are useless to me. What I need is to only add results 6-35 to the array. I've tried many different combinations of if, for and while conditionals but can't seem to get this to work. I'd love to hear what I'm doing wrong and finally get this to work.
$url = "www.theurl.com";
$html = new DOMDocument();
@$html->loadHtmlFile($url);
$xpath = new DOMXPath($html);
$nodelist = $xpath->query("//span[@class='mp-listing-title']");
$list = array();
$i = 0;
foreach ($nodelist as $n) {
$i++;
}
if ($i >=5 && $i <=35) {
$value = $n->nodeValue;
$list[] = $value;
}
Thanks for your help!