Merge / include PHP files with PHP?
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.
精彩评论