0

I'm trying to retrieve some information from a website using PHP Simple HTML Dom Parser. In the website there are many tables with the class "forumborder2" and inside them i want to get some information. In the next example i want the image source.

<table class="forumborder2" width=100% cellspacing=0 cellpadding=0 border=0 align=center>
        <tr>
            <td class="titleoverallheader2" background="modules/Forums/templates/chunkstyle/imagesnew/forumtop.jpg" style="border-top:0px; border-left:0px; border-right:0px;" width="100%" colspan=7 Align=left> 
                <b>Supernatural </b>(2005)&nbsp;&nbsp; - &nbsp;&nbsp;Enviada por: <b>AlJoSi</b>&nbsp;&nbsp; em 6 de Dezembro, 2011 (22:35:11)
            </td>
        </tr>
        <tr height=25>
            <td class="colour12" align=right width=100>
                <b>Idioma:</b> 
            </td>
            <td width=110 class="colour22"> 
                <img src="modules/Requests/images/fPortugal.png" width=18 height=12 border=0 alt='' title=''>
            </td>
        </tr> </table>

I did the following:

foreach($html->find('table[class="forumborder2"]')as $tr){
     echo $tr->children(1)->children(1)->src; }

This always gives the error: "Trying to get property of non-object". If i only go to $tr->children(1)->children(1) i can get <img src="modules/Requests/images/fPortugal.png" width=18 height=12 border=0 alt='' title=''> so why can't i access the src attribute.

2
  • What is "simple HTML dom parser"? And what error??? Commented Dec 10, 2011 at 14:53
  • @Jon, PHP Simple HTML DOM Parser. Changed the post with the error too. Commented Dec 10, 2011 at 15:35

1 Answer 1

4

can't you just grab all the images using the HTML Dom Parser? I'm not sure if if you're only grabbing it from a certain section of the HTML, but if you are, you could run a regex on the image source to get the ones you're looking for; here's a code snippet that might help:

// Create DOM from URL or file
$html = file_get_html('http://www.google.com/');

// Find all images 
foreach($html->find('img') as $element) 
   echo $element->src . '<br>';

// Find all links 
foreach($html->find('a') as $element) 
   echo $element->href . '<br>';

i hope this helps

Sign up to request clarification or add additional context in comments.

1 Comment

That would be my 2nd option. I would prefer to make some processing as i iterate trough each "forumborder2" tables and not later by iterating through the "images array".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.