Jump to content
ludo1960

An array, a string or an object???

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

Share this post


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

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

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.