Forum Moderators: coopster

Message Too Old, No Replies

IF ELSE statement help.

         

mrpyle

12:37 am on Apr 11, 2011 (gmt 0)

10+ Year Member



I wrote a SimpleXML script in PHP to parse data from an external XML file on another server.

Basically I just need an IF ELSE statement to check if the file is available, and if it is not, then simply display the message "server offline" to the user.

I know how IF ELSE statements work, but have confused myself with the formatting lol. And not sure just how to check if a page on another server is available or not.

IF http://12.123.12.1/somepage is available {then run script here }ELSE{ display "server offline"}


Any help is much appreciated, thanks.

Chuck

mrpyle

4:36 am on Apr 11, 2011 (gmt 0)

10+ Year Member



I figured it out...



if( ! $xml = simplexml_load_file('http://12.123.12.123/filename.xml') )
{
echo 'SERVER IS OFFLINE!';
}
else
{
run script here
}

coopster

6:58 pm on Apr 13, 2011 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, mrpyle.

That looks correct. You can find more information about PHP Control Structures [php.net] and their syntax in the online manual.