php - How to get url in <a> tag with Simple HTML DOM Parser? -


<ul id="prlist" class="v2">     <li class="tools">      </li>     <li class="firstrow">         <div class="i">             <a href="www.google.com" title="google" class="nc">                 <img src="something">             </a>         </div>     </li> </ul> 

how href attribute in <div class="i">?

i tried this-

$html = file_get_html($link); $urls = []; foreach($html->find('.i') $element) {    $url = $element->find('.nc')->href;    if (!in_array($url, $urls)) {        echo $url . "<br/>";        $urls[] = $url;    } } 

but received error:-

notice: trying property of non-object

and tried:-

$html = file_get_html($link); $html = $html->find('div.i'); $html -> find('a',0)->href;  $echo $html; 

but received error again:-

fatal error: call member function find() on array

you need below:-

$html = file_get_html($link); $urls = []; foreach($html->find('.i a') $element) {    $url = $element->href;    if (!in_array($url, $urls)) {        echo $url . "<br/>";        $urls[] = $url;    } } echo "<pre/>";print_r($urls); 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -