PHP merge static file details, _php tutorial

Source: Internet
Author: User
Tags configuration php

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 ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.