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

All 3 Replies

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:

thank you, it works, mr.cereal.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.