Reputation: 4740
I am successfully parsing an RSS feed with PHP, but want to return a message when the feed is empty. I have included the PHP File here to show you what I want to achieve.
I'm looking for it to break or stop executing, but print a message and stop at the point highlighted.
Thanks for your assistance.
Upvotes: 1
Views: 440
Reputation: 5416
DOMNode::getElementsByTagName returns a DOMNodeList object. To test if it's empty use its $length member.
if ($x->length == 0) {
exit('etc.');
}
Upvotes: 1
Reputation: 4951
There are multiple ways of ending the processing of a PHP script. The simplest way of doing so is to call the die()
or exit()
language constructs. You can also set a message using those functions, but then the program will not terminate successfully. Have a look at the official documentation on exit().
In short, if you want to display some text then exit successfully, then use this code:
echo "whatever you want to say";
exit(0);
Else, simply use this code:
exit("whatever you want to say");
By the way, I edited your php code, my modification is available at PasteBin. A diff with the original is also available at PastBin.
Upvotes: 0