unknown os platform
Free Beginner PHP Tutorials - die and exit functions | Whats-online.info
whats-online-info

Free Beginner PHP Tutorials - die and exit functions


Free
2016:09:26 / Science and Tutorials

How to use the die() function to print a message and exit the current script in PHP.





PHP die() and the exit()


The die()  and the exit() functions are more of the same. They Perform the same activity.
They print a message and end the current script. 

Mostly, these functions are used to terminate the current script if it returns false.

syntax

exit(message); die(message);

example

<?php     $filepath = '/path/file';     $file = fopen($filepath, 'r') or exit("unable to open file ($filepath)"); ?>

The above example will try to open and read the file in the $filepath directory. If the file does not exist in the specified directory, the exit () or die () function executes.











You may also like:


Leave a comment












Subscribe to get replies direct to your mailbox

Submit comment