How to stop the execution of a PHP script?

Use the exit() function to stop a PHP script. You can also write die(), it works exactly same. Any code after it will not run.

<?php
echo "Start<br>";

exit("Stopped here");

echo "This line never runs";
?>

Output:

Tutorials Class - Output Window

Start
Stopped here

To stop only a loop, use break instead. A full explanation is in PHP exit() function.


Learn more about the similar topics:
Tutorials
PHP Introduction
PHP Terminology
PHP Installation
PHP Syntax
PHP Comments
PHP exit() Function
Exercises & Assignments
Write a program to print “Hello World” using echo
Simple Tips for PHP Beginners
Experiment with Basic PHP Syntax Errors
Using phpinfo() – Display PHP Configuration & Modules
Interview Questions & Answers
What is PHP?
Who is the father of PHP?
What is the correct & common way to start and finish a PHP block of code?
What is Open Source Software?
What is the default extension of the PHP file?
What is the latest version of PHP?
What is the full form of PHP?