PHP生成的有线HTML DOM

I'm retrieving rss feed of blogs with this code

<?php     
$xml = ("https://serembangirl.wordpress.com/feed/");
$xmlDoc = new DOMDocument();
$xmlDoc->load($xml);
$x=$xmlDoc->getElementsByTagName('item');

for ($i=0; $i<=5; $i++) {
    $item_title=$x->item($i)->getElementsByTagName('title')
    ->item(0)->childNodes->item(0)->nodeValue;

    $item_link=$x->item($i)->getElementsByTagName('link')
        ->item(0)->childNodes->item(0)->nodeValue;

    $item_desc=$x->item($i)->getElementsByTagName('description')
        ->item(0)->childNodes->item(0)->nodeValue;

    $item_content=$x->item($i)->getElementsByTagName('encoded')->item(0)->nodeValue;
?>

<a href='#'>
    <div class="card">
        <div class='inner'>
            <p class='title'>
            <?php echo $item_title;?>
            </p>
            <p class='desc'> <?php echo $item_desc; ?> </p>
        </div>
    </div>
</a>
<?php } ?>

With above code, supposedly the should wrap the but it produced this instead :

http://i.imgur.com/YspeRe3.png

I really scratched my head solving this.

I think div within anchor tag is not recommended.

Check the actual source code that is generated by PHP. It will have the div inside the a.

div, p or other block level elements are not allowed inside an a element. The browser tries to "fix" your document.

Hint 1

Use XPath to fetch data from the DOM.

$xpath = new DOMXPath($xmlDoc);
foreach ($xpath->evaluate('//item') as $item) {
  $item_title = $xpath->evaluate('string(title)', $item);
  // ...
}

Hint 2

Don't forget the escaping if you output data as HTML source.

...
<p class='title'>
  <?php echo htmlspecialchars($item_title); ?>
</p>
...