How to terminate the execution of a script in PHP?

To terminate the execution of the script in PHP, the exit() function is used. It is a built-in function that outputs a message and then terminates the current script.

The message which you want to display is passed as a parameter to the exit() function. Script termination will be done by this function after displaying the message. It is an alias of die() function. It doesn’t return any value.

Syntax: exit(message)

Where the message is a parameter to be passed as an argument. It defines a message or status.

Example: The code given below will print a message and exit the current script.

<?php
$site = "https://www.interviewbit.com//";
fopen($site,"r")
or exit("Unable to connect to $site");
?>

Conclusion

PHP proves to be a great tool for writing dynamic web pages. It is not restricted to use by professional web developers. Non-technical users can also easily learn a few handy tricks to make their web pages easier to manage thereby making them more useful.