S3NTIN3L;10981757 wrote:
$dataset = $doc->getElementsByTagName("blog");
$node_count = $dataset->length;
This counts the number of "blog" elements in the document. Since I don't know what structure your document has, I can't really say what you need to do.
But if you for example have
<blog>
<post>
<date />
<title />
<body />
</post>
...
<post>
<date />
<title />
<body />
</post>
</blog>
You could do
# assuming there is just one blog element
$blogs = $doc->getElementsByTagName("blog");
$blog = $blogs->item(0);
$posts = $blog->getElementsByTagName("post");
$count = $posts->length;
With the above, you might also getElementsByTagName('title') since there is one title element per post element, so the count will be the same. But if not all posts have one title (some have 0, others have many) you can't rely on this.
However, you should not use HR in my opinion since this is far easier to control with css. If you change your output to
echo '<div class="post">';
echo "$title<br>";
echo "$date<br>";
echo "$body<br><br>";
echo '</div>';
And add the proper CSS styling, you will get the same effect
div.post + div.post
{
border-top: 1px solid black;
}