tags:

views:

123

answers:

4

Hello people,

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.

+1  A: 

Try this.

die("Your error message here");
Robert Duncan
Thanks Robert, I used your tip but it does not stop at that point.
Helen Neely
A: 

Can you just use die() to drop out at that point?

shambleh
A: 

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.

xav0989
+1  A: 

DOMNode::getElementsByTagName returns a DOMNodeList object. To test if it's empty use its $length member.

if ($x->length == 0) {
    exit('etc.');
}
GZipp
Thanks for your help - your code worked *out of the box* :))
Helen Neely