Re: fread problem
| From: | Ernest E Vogelsinger | Date: | Mon, 03 Mar 2003 08:57:02 +0000 |
| Subject: | Re: fread problem | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-137859@lists.php.net to get a copy of this message | ||
At 05:46 03.03.2003, Paul Cohen said:
--------------------[snip]--------------------
>Here is the code in my file and was taken directly from the manual:
>
> $filename = "test.php";
> $handle = fopen ($filename, "r");
> $contents = fread ($handle, filesize ($filename));
> fclose ($handle);
> echo $contents;
--------------------[snip]--------------------
You need to eval your code (not "exec"):
eval($contents);
Note that $contents need to be valid PHP for eval(). It must not start with
"<?php" since eval assumes it is code anyway. Some examples:
A) HTML with PHP interspersed
<b>Some HTML</b><br /><?php echo date('Y'); ?>Blah
you should
eval("?>$contents<?php");
B) Plain PHP
echo date('Y');
you should
eval($contents);
C) "Incomplete" PHP (missing semicolon)
call_this_function(blah)
you should
eval("$contents;");
If the PHP code returns some value, this will be the return of eval:
$contents="return time();";
$t = eval($contents);
You get the idea.
--
>O Ernest E. Vogelsinger
(\) ICQ #13394035
^ http://www.vogelsinger.at/