tags:

views:

31

answers:

2
<?php
// load SimpleXML
$entry = new SimpleXMLElement('http://bit.ly/c3IqMF', null, true);

echo <<<EOF
<table>
        <tr>
                <th>Title</th>
                <th>Image</th>                
        </tr>

EOF;
foreach($entry as $item) // 
{
        echo <<<EOF
        <tr>
                <td>{$item->title}</td>
                <td><img src="{$item->children('im', true)->image}"></td>       
        </tr>

EOF;
}
echo '</table>';
?>

The above php works but somehow, I got 8 empty table entities above the result

<tr>
            <td></td>
            <td><img src=""></td>       
    </tr>

What's wrong with the code? How do I get rid of the empty table entities?

A: 

Honestly, I think you are approaching this the wrong way. Since it seems that you are trying to parse an Atom feed, try using something designed for that, like Magpie RSS. It will probably save you a lot of time.

Ryan Gooler
Hi, I believe this can be done easily without Magpie RSS. I guess it would be my last effort. :D
webdev28
+2  A: 

The way you have it now it gets the <id>, <title>, <updated> from the the start of the xml. Actually you needed all the entry entries in the xml. So it should be $entry->entry

foreach($entry->entry as $item) // 
{
        echo <<<EOF
        <tr>
                <td>{$item->title}</td>
                <td><img src="{$item->children('im', true)->image}"></td>       
        </tr>

EOF;
}
dragosplesca
Works like a charm! ThanksI don't have enough reputation to vote up, sorry :p
webdev28
You can however to mark my answer as the accepted answer.
dragosplesca
i just knew about it :p
webdev28