3

メソッドを持つPHPスクリプトtest.phpがあるとします。

<?php
function execute($filename){
    //do something

    return $output;
}
?> 

また、別のPHPスクリプトもありますexecutable.php

<?php 
    echo "I am executed";
?>

次に、任意のコードを実行して2番目のファイルを実行し、execute呼び出したときに最初のメソッドからの出力を返すことができますecho execute('executable.php');か?

皆さんは私が何を意味するのか理解できると思います。

4

4 に答える 4

3

含まれているファイルがまだそれを行っていない限り、出力バッファリングを使用できます。

ob_start();

require $filename;

$content = ob_get_contents();

ob_end_clean();

return $content;
于 2013-01-15T03:43:13.777 に答える
3

ob_Startおよびを使用しob_get_contentsて、スクリプトの出力をキャプチャします。このようなものが機能するはずです:

<?php

function execute($filename){
    ob_start();
    include $filename;
    $output = ob_get_contents();
    ob_end_clean();
    return $output;
}
于 2013-01-15T03:45:32.647 に答える
0
<?php#test.php
    include 'executable.php';
    echo $test;
?>

<?php#executable.php
    $test = "I am executed";
?>
于 2013-01-15T03:44:42.900 に答える
0
function execute($filename){
    include_once($filename);
    }

$ filenameは、含めるファイルの名前です。これは役立つと思います...

これは関数呼び出しです。

 execute('abc.php');
于 2013-01-15T03:44:48.550 に答える