Current Location: Home> Function Categories> exit

exit

Output a message and exit the current script
Name:exit
Category:Miscellaneous
Programming Language:php
One-line Description:Print a message and exit the current script.

Definition and usage

exit() function outputs a message and exits the current script.

This function is an alias for the die() function.

Example

Print a message and exit the current script:

 <?php
$site = "http://www.gitbox.net/" ;
fopen ( $site , "r" )
or exit ( "Unable to connect to $site " ) ;
?>

Example explanation:

fopen() function attempts to open a connection to the specified URL in read-only mode. If the connection fails (for example, because the website is not accessible), the exit() function is called using the or operator, thus terminating the script and outputting the error message "Unable to connect to [Website Address]". This approach is useful when dealing with possible error situations, as it prevents the script from continuing to execute code that may cause problems.

grammar

 exit ( message )
parameter describe
message

Required. The message or status number to be printed before termination of the script.

The status number is not written to the output, but is only used as an exit status.

illustrate

If message is a string, the function outputs the string before exiting.

If message is an integer, this value will be used as the exit status. The value of the exit status is between 0 and 254. Exit status 255 is reserved by PHP and will not be used. Status 0 is used to successfully terminate the program.

Similar Functions
Popular Articles