[resolved] Using PHP to output Executable PHP

Discussion in 'Scripts, 3rd Party Apps, and Programming' started by expose, Apr 5, 2008.

  1. expose

    expose New Member

    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    <?php
     
    $page_home = "
    <?php
    $conn = mysql_connect(\"*******\", \"*******\", \"*******\") or die(mysql_error());
     
    mysql_select_db(\"*******\",$conn) or die(mysql_error());
    $get_content = \"SELECT * FROM `\".$site.\"_home_page`;\";
    $content = mysql_query($get_content,$conn);
    while($content_array = mysql_fetch_array($content)){
    $body = $content_array[data];
    $body_output .= \"<br /><br />\".$body;
    }
    $get_announce = \"SELECT * FROM `\".$site.\"_home_page_announce;\";
    $announce = mysql_query($get_announce,$conn);
    while($announce_array = mysql_fetch_array($announce)){
    $announcement = $announce_array[data];
    $announcement_output .= \"<div class=\"information\">\".$announcement.\"</div><br /><br/>\";
    }
     
    ?>
    ";
     
    ?>
    
    The above code is outputting:
    Code:
    <?php = mysql_connect("*******", "*******", "*******") or die(mysql_error());
    mysql_select_db("*******",) or die(mysql_error());
     
     = "SELECT * FROM `".."_home_page`;";
     = mysql_query(,);while( = mysql_fetch_array()){ 
    = ;
     .= "<br /><br />".;
    } 
    = "SELECT * FROM `".."_home_page_announce;"; 
    = mysql_query(,);
     
    while( = mysql_fetch_array()){
     = ;
     .= "<div class="information">".."</div><br /><br/>";
    }
     
    ?>
    
    And I need it to output:

    Code:
    <?php
    $conn = mysql_connect("*******", "*******", "*******") or die(mysql_error());
    mysql_select_db(\"expose_expose\",$conn) or die(mysql_error());
    $get_content = "SELECT * FROM `".$site."_home_page`;";
    $content = mysql_query($get_content,$conn);
    while($content_array = mysql_fetch_array($content)){
    $body = $content_array[data];
    $body_output .="<br /><br />".$body;
    }
    $get_announce = "SELECT * FROM `".$site."_home_page_announce;";
    $announce = mysql_query($get_announce,$conn);
    while($announce_array = mysql_fetch_array($announce)){
    $announcement = $announce_array[data];
    $announcement_output .= "<div class=\"information\">".$announcement."</div><br /><br/>\";
    }
     
    ?>
     
    
    Edit:
    I fixed it.

    Code:
    <?php
    
    $site_home = fopen("test_home.php", "w+");
    
    
    //add add code to files
    
    /*** Begin Template File ***/
    $test_home = "
    <?php
    
    $"."conn = mysql_connect(\*******\", \*******\", \*******\") or die(mysql_error());
    mysql_select_db(\*******\",$conn) or die(mysql_error());
    
    $"."get_content = \"SELECT * FROM `\".$"."site.\"_home_page`;\";
    $"."content = mysql_query($get_content,$conn);
    
    while($"."content_array = mysql_fetch_array($"."content)){
    $"."body = $"."content_array[data];
    
    $"."body_output .= \"<br /><br />\".$"."body;
    }
    
    $"."get_announce = \"SELECT * FROM `\".$"."site.\"_home_page_announce;\";
    $"."announce = mysql_query($"."get_announce,$"."conn);
    
    while($"."announce_array = mysql_fetch_array($"."announce)){
    $"."announcement = $"."announce_array[data];
    
    $"."announcement_output .= \"<div class=\\\"information\\\">\".$"."announcement.\"</div><br /><br/>\";
    }
    
    ?>
    ";
    fwrite($site_home,$test_home);
    
    fclose($site_home);
    
    ?>
    
     
    Last edited: Apr 5, 2008
  2. woiwky

    woiwky New Member

    Messages:
    390
    Likes Received:
    0
    Trophy Points:
    0
    You can just place a backslash before a $ to escape it from being interpreted as a variable. However, if you don't want to have to escape $ and " in a string, then just enclose the text in single quotes.
     

Share This Page