假设我有一个PHP脚本test.php,它有一个方法
<?php
function execute($filename){
//do something
return $output;
}
?>
我还有另一个PHP脚本executable.php
<?php
echo "I am executed";
?>
然后我可以运行任何代码来执行第二个文件并在我调用execute
时从第一个方法echo execute('executable.php');
返回输出吗?
我想你们都能理解我的意思。
答案 0 :(得分:2)
您可以使用output buffering,只要包含的文件尚未执行此操作:
ob_start();
require $filename;
$content = ob_get_contents();
ob_end_clean();
return $content;
答案 1 :(得分:2)
使用ob_Start
和ob_get_contents
捕获脚本的输出。这样的事情应该有效:
<?php
function execute($filename){
ob_start();
include $filename;
$output = ob_get_contents();
ob_end_clean();
return $output;
}
答案 2 :(得分:0)
<?php#test.php
include 'executable.php';
echo $test;
?>
<?php#executable.php
$test = "I am executed";
?>
答案 3 :(得分:0)
function execute($filename){
include_once($filename);
}
$ filename是要包含的文件的名称..我认为这会对你有帮助......
这是函数调用..
execute('abc.php');