Page 1 of 1

Eval() Problem.

Posted: Sat Aug 20, 2011 9:20 am
by ThatPerson
I am trying to create a simple type of Wiki, one where the control panel is the the database and it has an easy to use interface. The reason I am making it is to distribute a open source project I have been working on, and because of this I need to have a download link. The problem: The script is getting *text* from the database and displaying it, and not the download link.

To fix this I came across eval() however I have run into a problem: The PHP Manual (http://php.net/manual/en/function.eval.php) is not the most descriptive on how to use it I have ever seen.

The code is:

Code: Select all

$text = eval('$note1text');
Where $note1text is:

Code: Select all

<?php echo "<html><head></head><body><p>Hello There</p></body></html>"; ?>
However it errors with:

[text]Parse error: syntax error, unexpected $end in index.php(56) : eval()'d code on line 1[/text]

From reading the PHP page it says something about

[text]eval() returns NULL unless return is called in the evaluated code, in which case the value passed to return is returned. If there is a parse error in the evaluated code, eval() returns FALSE and execution of the following code continues normally. It is not possible to catch a parse error in eval() using set_error_handler(). [/text]

However if I am trying to get it to run the code, how would I use return?

Re: Eval() Problem.

Posted: Sat Aug 20, 2011 9:25 am
by oscardog
So in the database you have "echo "<html><head></head><body><p>Hello There</p></body></html>";" and that is being retrieved from the database?

If so, I'm pretty sure you don't need single quotes around $note1text in your eval call.

Re: Eval() Problem.

Posted: Sat Aug 20, 2011 9:42 am
by ThatPerson
I just removed the single quotes, yet it returns with:

[text]Parse error: syntax error, unexpected '<' in /home/bentatma/public_html/swarm/index.php(56) : eval()'d code on line 1[/text]

Re: Eval() Problem.

Posted: Sat Aug 20, 2011 10:24 am
by ThatPerson
Ah, the problem was the <?php tags. I removed them and it works.

Re: Eval() Problem.

Posted: Sat Aug 20, 2011 10:35 am
by phphelpme
ahhh, so you were saving the php tags within the string value... Man I bet that did your head in. lol

Nice one for figuring that out.

Best wishes