Допустим, файл test.php выглядит следующим образом:
<?php
echo 'Hello world.';
?>
Я хочу сделать что-то вроде этого:
$test = include('test.php');
echo $test;
// Hello world.
Кто-нибудь может указать мне правильный путь?
Edit:
Моей первоначальной целью было вытащить из базы данных код PHP, смешанный с HTML, и обработать его. Вот что я в итоге сделал:
// 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);
}