Eval Function and PHP in a PHP variable

Discussion in 'PHP' started by adbox, Jan 28, 2010.

  1. #1
    Hey,

    I am trying to include and include_once(''); statement in my $html.=""; variable.

    I need it to be something like this

    
    
    $html = "<link rel='stylesheet' type='text/css' href='./../style.css' media='screen' />";
    $html .= "</head>";
    $html .= "<?php include_once('file.php')'; ?>";
    
    Code (markup):
    How can I do this using the eval()???
     
    adbox, Jan 28, 2010 IP
  2. HivelocityDD

    HivelocityDD Peon

    Messages:
    179
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try

    
    $html = "<link rel='stylesheet' type='text/css' href='./../style.css' media='screen' />";
    $html .= "</head>";
    $html .= "<?php include_once('file.php'); ?>";
    
    eval("\$html = \"$html\";");
    
    echo $html;
    
    
    PHP:
     
    HivelocityDD, Jan 28, 2010 IP
  3. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #3
    <?php
    
    $html = <<<HTML
    <link rel='stylesheet' type='text/css' href='./../style.css' media='screen' />
    </head>
    HTML;
    
    $html2 = include_once("test.php");
    
    eval("\$html2 = \"$html2\";");
    
    echo $html;
    ?>
    PHP:
     
    Last edited: Jan 28, 2010
    danx10, Jan 28, 2010 IP
  4. adbox

    adbox Well-Known Member

    Messages:
    906
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    155
    Digital Goods:
    1
    #4
    Great I went with Hive's and that works perfect.

    Now I'd like to do something like this:
    
    $html .= "<?php $var1='$var1'; ?>";
    $html .= "<?php $var2='$var2'; ?>";
    
    PHP:
    I'm having trouble though. Any suggestions?
     
    adbox, Jan 28, 2010 IP
  5. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Backslash your dollar signs. But are you sure you're going down a good road? What are you actually trying to achieve?
     
    SmallPotatoes, Jan 28, 2010 IP
  6. insert

    insert Peon

    Messages:
    148
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    don't use eval until if there's no another way... if you'll want to help with php, just pm me...
     
    insert, Jan 28, 2010 IP
  7. adbox

    adbox Well-Known Member

    Messages:
    906
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    155
    Digital Goods:
    1
    #7
    is there a security risk that I am not aware of? I am building a content automation system for building pages on the fly. All this is for my templating.
     
    adbox, Jan 28, 2010 IP
  8. adbox

    adbox Well-Known Member

    Messages:
    906
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    155
    Digital Goods:
    1
    #8
    
    $html .= "<?php \$var1='".$var1."'; ?>";
    $html .= "<?php \$var2='".$var2."'; ?>";
    
    
    ...
    
     eval("\$html = \"$html\";");
     $fh = fopen($file, 'w');
     fwrite($fh, $html);
     fclose($fh); 
    
    PHP:
    : / no luck the above outputs the actual stored data on the file I am writing to, even when I backslash like above.
     
    Last edited: Jan 28, 2010
    adbox, Jan 28, 2010 IP