The php merge static file is detailed,
Configure PHP.ini
Change configuration item (required) Auto_prepend_file = "C:\xampp\htdocs\auto_prepend_file.php"
Change configuration item (optional) Allow_url_include = On
auto_prepend_file.php File Contents
Copy the Code code as follows:
<?php
/**
* Introduction of static files
* @param {array|string} relative path
* @param {string} The path where the script is currently executing __file__
*
*/
function import_static ($files, $path =null) {
Change the execution path of the current script
$old _dir = GETCWD ();
$tmp _dir = (isset ($path))? DirName ($path): DirName (__file__);
ChDir ($tmp _dir);
Organize include files
if (!is_array ($files)) {
$tmp = Array ();
$tmp [] = $files;
$files = $tmp;
}
Send header information
if (isset ($files [0])) {
if (Stripos ($files [0], '. js ')!== false) {
$header _str = ' content-type:text/javascript ';
} elseif (Stripos ($files [0], '. css ')!== false) {
$header _str = ' content-type:text/css ';
}
if (!ob_get_contents ()) {
Header ($header _str);
}
}
Introduce the Include file
foreach ($files as $key = = $value) {
Require_once ($value);
}
Change back to the execution path of the current script
ChDir ($old _dir);
}
?>
How to use
Copy the Code code as follows:
"A.js", "B.js" and ".. /c.js "is the JS file to be merged, merge it into base.js.php, then the code in base.js.php is as follows:
<?php
Import_static (Array (
' A.js ',
' B.js ',
'.. /c.js ',
'.. /moduleb/all.js.php '//can also refer to. php files
), __file__);
?>
It can be introduced in HTML pages.
Product on-line before, using batch processing files for processing, mainly do two aspects of work
1. Output "*.js.php" to "*.js" file and delete "*.js.php". Command line: PHP *.js.php > *.js
2. Replace the reference "*.js.php" in the HTML page with "*.js". Preg_replace ()
The Ps:import_static function solves the problem of handling relative paths in PHP with include ().
The above is the entire content of this article, more detailed information please look forward to the following articles
http://www.bkjia.com/PHPjc/911904.html www.bkjia.com true http://www.bkjia.com/PHPjc/911904.html techarticle php Merge static file details, configuration php.ini change configuration item (must) Auto_prepend_file = "C:\xampp\htdocs\auto_prepend_file.php" Change configuration item (optional) Allow_url_ Include = O ...