比方說文件test.php的是這樣的:在PHP中獲取包含在字符串中的結果?
<?php
echo 'Hello world.';
?>
我想要做這樣的事情:
$test = include('test.php');
echo $test;
// Hello world.
任何人都可以點我正確的道路?
編輯:
我最初的目標是拉與HTML混合在一起PHP代碼從數據庫中,並對其進行處理。這是我最終做的:
// Go through all of the code, execute it, and incorporate the results into the content
while(preg_match('/<\?php(.*?)\?>/ims', $content->content, $phpCodeMatches) != 0) {
// Start an output buffer and capture the results of the PHP code
ob_start();
eval($phpCodeMatches[1]);
$output = ob_get_clean();
// Incorporate the results into the content
$content->content = str_replace($phpCodeMatches[0], $output, $content->content);
}
保存一行:'$ output = ob_get_clean();';-) – 2009-11-29 00:05:03
太棒了,謝謝! – 2009-11-29 12:23:35