Jump to content

An array, a string or an object???


ludo1960

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? 

Link to comment
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 ;
    }
}

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.