<?php
include 'simple_html_dom.php';

function get_url_contents($url){
    $crl = curl_init();
    $timeout = 5;
    curl_setopt ($crl, CURLOPT_URL,$url);
    curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
    $ret = curl_exec($crl);
    curl_close($crl);
    return $ret;
}

$url = 'http://rural.nic.in';
$outhtml = get_url_contents($url);
$html= str_get_html($outhtml);

foreach($html->find('li')as $item) {
    echo $item."<br>";
}
//print_r($outhtml);
?>

I wish to print only the URLs listed under the tabs separately, which is in the middle of the page. I tried to use "li" in foreach($html->find('li')as $item) but I did not get the desired result!
Please help! Thanks!

You need to use the string functions of php - http://php.net/manual/en/ref.strings.php - specifically, strpos, strlen, substr. Is this '$html->find('li') method part of a defined class? I think javascript is more suited to looping through DOM elements and grabbing the href location.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.