开发者

Merge / include PHP files with PHP?

开发者 https://www.devze.com 2023-02-02 07:24 出处:网络
In my local environment I have many small PHP files in different folders. I use \"include\" or \"require once\" to run them toget开发者_JAVA技巧her.

In my local environment I have many small PHP files in different folders. I use "include" or "require once" to run them toget开发者_JAVA技巧her.

I'm going to upload my little project to the web but I only want to upload it as one PHP file. I need to merge the files together.

I found a nice function that makes an include as a string.

function get_include_contents($filename)
{
    if (is_file($filename)) {
        ob_start();
        if(file_exists($filename)) include $filename;
        $contents = ob_get_contents();
        ob_end_clean();
        return $contents;
    }
    return false;
}

It gives me the HTML result, not the PHP code. I need to get the PHP code.


function get_include_contents($filename)
{
    if (is_file($filename) && is_readable($filename)) {
        return file_get_contents($filename);
    }
    return false;
}


include is in effect running the code within $filename. Instead, you should use file_get_contents(), which will return the raw contents of the file, without parsing them.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号