Re: require?fread?fopen?
| From: | Rasmus Lerdorf | Date: | Thu, 22 Jun 2000 16:56:24 +0000 |
| Subject: | Re: require?fread?fopen? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-2656@lists.php.net to get a copy of this message | ||
> GOAL: I'd like to assign a big HTML contents (with PHP embedded) to a
> single
> variable so that I can send it as a MIME attachement by email.
>
> i.e. $my_var = <The whole HTML contents>
>
> PROBLEM:
> I tried saving the HTML+PHP codes into a file called "html_ver.inc",
> then read
> it with the following commands.
>
> $filename="./html_ver.inc";
> $fp = fopen("$filename", "r");
> $html_msg = fread($fp,filesize($filename));
> fclose($fp);
>
> However, when I do "echo $html_msg" within the script, it only outputs
> the HTML
> codes but the PHP variables inside html_ver.inc doesn't show anything.
>
> Why?
Because fread() reads in the bytes directly. It does not put the data
stream through the PHP parser. If you want PHP tags in your data stream
evaluated you need to feed the string through eval();
-Rasmus