Helen Neely
Helen Neely

Reputation: 4740

Parsing RSS feeds with PHP

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

Answers (4)

GZipp
GZipp

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

T0xicCode
T0xicCode

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

Steven
Steven

Reputation: 3843

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

Upvotes: 0

Robert Duncan
Robert Duncan

Reputation: 510

Try this.

die("Your error message here");

Upvotes: 1

Related Questions