Home > Backend Development > PHP Problem > How to use the exit() function in PHP

How to use the exit() function in PHP

autoload
Release: 2023-03-09 11:08:01
Original
2542 people have browsed it

How to use the exit() function in PHP

exit() The function outputs a message and exits the current script. This function is an alias of the die() function.

Syntax:

exit    ( string $status )
Copy after login
exit    ( int $status )
Copy after login
  • If $status is a string, the function will print $status before exiting .

  • If $status is an int, the value will be used as the exit status code and will not be printed. Exit status codes should be in the range 0 to 254, and the exit status code 255, which is reserved by PHP, should not be used. Status code 0 is used to terminate the program successfully.

1. If the parameter is a string:

<?php

    $filename = &#39;./exit.html&#39;;
    $file = @fopen($filename, &#39;r&#39;)
    or exit("打开文件($filename)失败");
?>
Copy after login

Output: Open file (./exit .html) failed because the file exit.html does not exist in the current path.

2. If the parameter is empty:

<?php
$filename = &#39;./exit.html&#39;;
echo "此处使用了exit()";

$file = @fopen($filename, &#39;r&#39;)
    or exit();
?>
Copy after login

Output: exit() is used here

3. Only contains status code

<?php
exit(1);
exit(0376); 
?>
Copy after login

Recommendation:2021 PHP interview questions summary (collection) 》《php video tutorial

The above is the detailed content of How to use the exit() function in PHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template