Re: eval function - I don't know what I am doing wrong...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi.

Please read the manual on php.net. It's possibly the best manual I've read for any programming language.

Here's some of your code cleared up:

<?php

$name  = 'Mary';
$name2 = 'Ana';
//to get the values of the vars above evaluated, use double quotes
$a = "My friends are called $name and $name2<br>";
//don't use eval unless you know what you are doing. 
//The eval code you used would likely throw an error.
//To put quotes around a variable use a mixture of single and 
//double quotes (1) or escape the quotes (2)
$str = '"' . $a . '"'; //technique 1
$str = "\"$a\""; //technique 2
?>

The rest of the code is meaningless. Please RTFM.

Regards,

Shadow


--- In php-objects@xxxxxxxxxxxxxxx, "gregaizi" <gregaizi@...> wrote:
>
> All manual suggest about the same code as examples:
> <code>
> <?php
> $name = 'Mary';
> $name2 = 'Ana';
> $a = 'My friends are called $name and $name2';
> print $a . "<br>";
> eval("\$a = \"$a\";");
> print $a . "<br>";
> ?>
> 
> </code> 
> and it works.
> 
> But it does not work in my code
> <code>
> $s=file_get_contents($_GET['p']); //PAGE
> if (!eval("\$str = \"$s\" ;")) {fwrite($f,"error evaluating!\n"); $errorflag=true; } 
> </code>
> the content of the $s is a php-program ECHOing some data...
> 
> Or how I can call php for a program, catch and use all of its output in the calling php-program?
> 
> Thanks in advance
>



[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux