#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Posts
    3
    Rep Power
    0
    Hi.

    I'm having problems with eval(); what does it evaluate?

    I know it might be a silly question but I can't get it to behave the way I want it to.

    It's no problem if all I want to do is parse, say, $PHP_SELF to a proper value:
    $String1="This is $PHP_SELF!";
    eval("$String2="$String1";");
    echo $String2;
    produces the correct result, i.e. $PHP_SELF gets parsed correctly.

    This way to evaluate a string containing PHP code also works out:
    $TEST="print("This is a test!");";
    $DBCode="$TEST";
    eval("$DBCode");
    This produces the output "This is a test!" (without the quotes). I would get the same result by evaluating $TEST directly but I'm trying to simulate how the 'real' script is working.

    I need to mix HTML and PHP though. This combination works:
    $TEST="?><p><? print("This is a test!"); ?><p><?";
    eval("$TEST");
    Notice how I escape in and out of PHP with the <? and ?> tags. Here's where the first 'problem' arose; eval() won't accept the <?php entry tag! On purpose or just a neglection?

    The problems begins when I pull code from the database. This is one piece that won't work (it's inserted and retrieved with escaped characters where needed):

    ?><form method="post" action="<? $PHP_SELF ?>" name="NyttMaterial01">
    <table width="100%" border="0" cellspacing="1" cellpadding="0">
    <tr>
    <td class="Header4" colspan="6"><? HTML_DoSelect("","Name",""); ?></td>
    </tr>
    </table>
    </form><?

    Now I get the all too familiar error:
    Parse error: parse error in Unknown on line 1
    HTML_DoSelect() is my own function but it's no different with print().
    Infact, this code gives me the same error:
    ?><form method="post" action="<? $PHP_SELF ?>" name="NyttMaterial01">
    </form><?

    I have no idea how to get any further with this. Can anyone who knows how this damn function *really* works let me (and the rest on this list) know? I'd be extremely grateful. Hopefully it's just me messing things up... 8)


    Best regards,
    Martin Edelius

    Spirex Digital Design
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    31
    Rep Power
    15
    eval('?><form method="post" action="<? echo $PHP_SELF ?>" name="NyttMaterial01">
    <table width="100%" border="0" cellspacing="1" cellpadding="0">
    <tr>
    <td class="Header4" colspan="6"><? ?></td>
    </tr>
    </table>
    </form><?');

    That works for me (notice the <? echo $PHP_SELF ?> and <? ?> instead of <? HTML_DoSelect("","Name",""); ?> ) so I have no idea what you're doing wrong.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Posts
    3
    Rep Power
    0
    Well, the problem begins when I grab the code from the database. I've tried every possible solution but I can't get it to work...

    Well, atleast it seems as eval() *does* work as intended and that it's probably something else with my code.

    Thanks for the feedback!

    -- Martin

Similar Threads

  1. eval() detecting syntax errors
    By juhasev in forum PHP Development
    Replies: 2
    Last Post: February 5th, 2004, 03:32 PM
  2. eval is hurting me! please help!
    By poncenby in forum HTML Programming
    Replies: 2
    Last Post: January 14th, 2004, 07:01 AM
  3. parse order question
    By wannabe in forum PHP Development
    Replies: 5
    Last Post: December 13th, 2003, 09:06 PM
  4. Losing $var set in first eval() in second eval()
    By ShepMode in forum PHP Development
    Replies: 6
    Last Post: October 1st, 2003, 12:46 PM
  5. eval and use
    By the_pedestrian in forum Perl Programming
    Replies: 4
    Last Post: July 28th, 2002, 02:15 PM

IMN logo majestic logo threadwatch logo seochat tools logo