i try to get comment count from a blog post use blog feed. i want to get number inside

<slash:comments>0</slash:comments>

i use this syntax but did not work:

<?php
$feed = file_get_contents("http://www.trenologi.com/feed/");
$xml = new SimpleXmlElement($feed);
foreach($xml->channel->item as $entry) {
$comment = mysql_real_escape_string("$entry->slash:comments");
echo "$comment";
}
?>

i think the error is $entry->slash:comments, what must i write to change slash:comments to get comment count?

thank you daniweb friends.

Recommended Answers

Hi,

you have to set the namespace that defines slash, so:

<?php

$feed = file_get_contents("http://www.trenologi.com/feed/");
$xml = new SimpleXmlElement($feed);
$xml->registerXPathNamespace('slash', 'http://purl.org/rss/1.0/modules/slash/');

$result = $xml->xpath('//slash:comments');

foreach($result as $pcount)
{
    echo $pcount;
}

Documentation:

Jump to Post

All 3 Replies

It is painful to see that you're putting quotations around plain variables...