Re: getting an variable value from an array entry
| From: | Curt Zirzow | Date: | Mon, 01 Dec 2003 05:22:59 +0000 |
| Subject: | Re: getting an variable value from an array entry | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-171428@lists.php.net to get a copy of this message | ||
* Thus wrote zhuravlev alexander (zaa@ulstu.ru):
>
> % cat temp.txt
> Temperature $temp degree.
> % cat temp.php
> <?php
>
> $temp = '5';
>
> $filename = "./temp.txt";
> $handle = fopen ($filename, "r");
> $code = fread ($handle, filesize ($filename));
> fclose ($handle);
> print $code."<br>";
> eval("\$result = \"".addslashes($code)."\";");
> echo $result;
> ?>
- or -
$code = file_get_contents($filename);
$result = str_replace('$temp', $temp, $code);
echo $results;
Curt
--
If eval() is the answer, you're almost certainly asking the
wrong question. -- Rasmus Lerdorf, BDFL of PHP