Jump to content

Recommended Posts

Hi guys,

I'm using http://simplehtmldom.sourceforge.net/manual.htm  and my code is :

$html = file_get_html('test/somefile.html');

if(!empty($html)){    
    foreach($html->find('ul') as $ul) {
        $testul[] =  $ul->outertext;
        if (isset($testul[2])) {
        $links = $testul[2] ; }
    }
    $html2 = str_get_html($links) ;
    foreach($html2->find('a') as $a) {
        $links2 = $a->href ;
    }
}

echo '<pre>',print_r($links, 1),'</pre>'; 

The links array prints out a nice html page, and I would like to grab all the a tags for that page. I tried $html2 = str_get_html($links) ;  as you see in my code above, but the $links2 page only prints out the last a tag. So I need to either convert the $html2 string to an array or find a way to extract the (a) tags from a string. Any ideas? 

Edited by ludo1960
Link to comment
https://forums.phpfreaks.com/topic/308285-an-array-a-string-or-an-object/
Share on other sites

And just after I posted I found the answer. grrrrrrrrrr!!!!!! 

if(!empty($html)){    
    foreach($html->find('ul') as $ul) {
        $testul[] =  $ul->outertext;
        if (isset($testul[2])) {
        $links = $testul[2] ; }
    }
    $html2 = str_get_html($links) ;
    foreach($html2->find('a') as $a) {
        $links2[] = $a->href ;
    }
}

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.