PHP merge static files _php Tutorial

Source: Internet
Author: User
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

1. 2./**
3. * Introduction of static files
4. * @param {array|string} relative path
5. * @param {string} The path where the script is currently executing __file__
6. *
7. */
8. Function import_static ($files, $path =null) {
9.//Change the execution path of the current script
$old _dir = GETCWD ();
One. $tmp _dir = (isset ($path))? DirName ($path): DirName (__file__);
ChDir ($tmp _dir);
13.//organize Include files
if (!is_array ($files)) {
$tmp = Array ();
$tmp [] = $files;
$files = $tmp;
18.}
19.//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 ';
25.}
if (!ob_get_contents ()) {
Header ($header _str);
28.}
29.}
30.//introduction of included Files Www.2cto.com
. foreach ($files as $key = = $value) {
Require_once ($value);
33.}
34.//change back to the execution path of the current script
ChDir ($old _dir);
36.}
Panax?>.

How to use
"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:

1. 2. Import_static (Array (
3. ' A.js ',
4. ' B.js ',
5. '. /c.js ',
6. '. /moduleb/all.js.php '//can also refer to. php files
7.), __file__);
8.?>
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 ().
Cond...


Excerpt from Rain man

http://www.bkjia.com/PHPjc/478272.html www.bkjia.com true http://www.bkjia.com/PHPjc/478272.html techarticle 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 ...

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