Diciamo che il file test.php si presenta così:Ottieni i risultati di un inclusione in una stringa in PHP?
<?php
echo 'Hello world.';
?>
voglio fare qualcosa di simile:
$test = include('test.php');
echo $test;
// Hello world.
Qualcuno può puntare a me la strada giusta?
Edit:
Il mio obiettivo iniziale era quello di tirare il codice PHP mescolati con l'HTML da un database e di processo. Ecco cosa ho finito per fare:
// 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);
}
salvare una riga: '$ output = ob_get_clean();' ;-) –
Impressionante, grazie! –