Example Analysis of auto_prepend_file and auto_append_file usage in PHP, autoprependfile
This example describes how to use auto_prepend_file and auto_append_file in PHP. It is a practical technique in PHP programming. Share it with you for your reference. The specific method is as follows:
To send the file require to the top and bottom of all pages.
Method 1: add the require statement to the top and bottom of all pages.
For example:
Require ('header. php'); // require ('footer. php') in the content of the page body ');
However, if you need to modify the require file path at the top or bottom of the page, you need to modify all the page files. In addition, it is troublesome to add the require statement to each page.
Method 2: Use auto_prepend_file and auto_append_file to specify the require file at the top and bottom of all pages.
Php. ini contains two items:
Auto_prepend_file: load the file at the top of the page
Auto_append_file: load the file at the bottom of the page
To use this method, you do not need to change any pages. to modify the require file at the top or bottom, you only need to modify the values of auto_prepend_file and auto_append_file.
For example, modify php. ini and the values of auto_prepend_file and auto_append_file.
auto_prepend_file = "/home/fdipzone/header.php"auto_append_file = "/home/fdipzone/footer.php"
Restart the server after modification, so that the top and bottom of all pages will be require/home/fdipzone/header. php and/home/fdipzone/footer. php
Note: auto_prepend_file and auto_append_file can only require one PHP file, but this PHP file can require multiple other PHP files.
If you do not need all the pages to be on the top or bottom of the require file, you can specify a page file in a folder to call auto_prepend_file and auto_append_file
Add the. htaccess file to the folder that needs to load files at the top or bottom. The content is as follows:
php_value auto_prepend_file "/home/fdipzone/header.php"php_value auto_append_file "/home/fdipzone/footer.php"
In this way, the page files in the specified. htaccess folder will load/home/fdipzone/header. php and/home/fdipzone/footer. php. Other page files will not be affected.
Use. htaccess settings are flexible. You do not need to restart the server or administrator permissions. The only drawback is that each file read and interpreted in the directory must be processed each time, instead of processing it once at startup, the performance will be reduced.
I hope this article will help you learn PHP programming.
Php return usage, functions, and examples
Return () also terminates the execution of the eval () statement or script file. If it is called globally, the current script file stops running. If the current script file is included () or require (), it is controlled to return the call file. In addition, if the current script is include (), the return () value will be treated as the return value of the include () call. If return () is called in the main script file, the script stops running. If the current script file is specified by the configuration option auto_prepend_file or auto_append_file in php. ini, the script file stops running. B. php <? Phpecho "B"; return; echo "c"; // will not be executed here? The above result will output ba
Php return usage, functions, and examples
If you call the return () statement in a function, the execution of the function is immediately ended and its parameters are returned as function values. Return () also terminates the execution of the eval () statement or script file.
If it is called globally, the current script file stops running. If the current script file is included () or require (), it is controlled to return the call file. In addition, if the current script is include (), the return () value will be treated as the return value of the include () call. If return () is called in the main script file, the script stops running. If the current script file is specified by the configuration option auto_prepend_file or auto_append_file in php. ini, the script file stops running.
Example:
<? Php
Function min ($ a, $ B ){
Return $ a <$ B? $ A: $ B; // here is the return value of the function. The following statement is no longer executed.
$ A ++;
}
?>
A. php
<? Php
Include ("B. php ");
Echo "";
?>
B. php
<? Php
Echo "B ";
Return;
Echo "c"; // This will not be executed
?>
The above result will output ba