note 85557 deleted from function.include by danbrown
| From: | danbrown@php.net | Date: | Mon, 18 May 2009 00:54:40 +0000 |
| Subject: | note 85557 deleted from function.include by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-155444@lists.php.net to get a copy of this message | ||
Note Submitter: Mwyann
----
I have another function implementation of the include_text, that works better but makes use of the
filesystem... Here it is :
<?php
function include_text($__text,$__exported){
foreach($__exported as $__name => $__value) {
$$__name = $__value;
}
$__filename = tempnam('/tmp/','Form');
file_put_contents($__filename,$__text);
ob_start();
include $__filename;
$__contents = ob_get_contents();
ob_end_clean();
unlink($__filename);
return $__contents;
}
?>
Usage example (the code speaks for itself) :
<?php
// ....
$exportedVars['Names'] = $Names;
$exportedVars['Data'] = $Data;
$includedResult = include_text($importedText,$exportedVars);
echo $includedResult; // Or make anything you want with it
// ....
?>
Note : it works nicely but doesn't return the exported vars if they are changed. I didn't
neede that, so figure it out yourself if you need it (and share it !)