Re: getting an variable value from an array entry
| From: | zhuravlev alexander | Date: | Sun, 30 Nov 2003 21:16:07 +0000 |
| Subject: | Re: getting an variable value from an array entry | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-171420@lists.php.net to get a copy of this message | ||
On Sun, Nov 30, 2003 at 01:04:08PM -0800, Ian Truelsen wrote:
> On Sun, 30 Nov 2003 21:44:50 +0100
> "Bronislav Klucka" <Bronislav.Klucka@pro2-soft.com> wrote:
>
> > The temperature is $$temp
> >
> Unfortunately, that is not working for me. I have tried changing it in
> the text file, but that just outputs $$temp instead of the value of
> $temp. What I have is the array words, for which the relevant entry is
> words[3] being equal to "$temp". What I need to be able to do is to
> print $words[3]; in such a way that it outputs the value of $temp and
> not the value of $words[3].
>
> I also tried print $$words[3] but that outputs nothing. I tried print
> $($words[3]); but that gives a parse error. And print ${$words[3]}
> prints out nothing.
Use eval. http://www.php.net/eval
% 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;
?>
-- zhuravlev alexander
u l s t u n o c
(zaa@ulstu.ru)