elite_prodigy Posted April 5, 2008 Share Posted April 5, 2008 $page_home = " <?php $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/>\"; } ?> " I'm using the above code to output PHP into a file that I'm writing. But I can tell just by looking at the code that it will reder an error when executed in the page I'm planning to put it on.\ This is the section that troubles me: <?php $announcement_output .= \"<div class=\"information\">\".$announcement.\"</div><br /><br/>\"; ?> When that line outputs, it will look like this: $announcement_output = "<div class="information">".$announcement."</div><br /><br />"; I want it to look like this: $announcement_output = "<div class=\"information\">".$announcement."</div><br /><br />"; I can't figure out how to outpu this the way I want. I can't get the formatting down. Link to comment https://forums.phpfreaks.com/topic/99707-solved-using-php-to-output-executable-php/ Share on other sites More sharing options...
marcus Posted April 5, 2008 Share Posted April 5, 2008 You only escape quotes if you need to use them in a quote, but using it like you are remove the slashes $you = "this will show \"real quotes\""; $me = "this will show ".$a_variable." without the quotes"; Link to comment https://forums.phpfreaks.com/topic/99707-solved-using-php-to-output-executable-php/#findComment-510067 Share on other sites More sharing options...
elite_prodigy Posted April 5, 2008 Author Share Posted April 5, 2008 I don't think I explained what I'm trying to do then, sorry. I'm using PHP to build a file for users when they register. The site is mostly database driven, to prevent users from using their site for deviant purposes. This code is a snippet from the registration file. The line in particular is being used to build the Home page which has some PHP at the top to call the data from the MySQL database. I need to output the code in a way that it is formatted to work. I'm writing the code so that it will be sent to another file and still work. Maybe that will help? Link to comment https://forums.phpfreaks.com/topic/99707-solved-using-php-to-output-executable-php/#findComment-510071 Share on other sites More sharing options...
elite_prodigy Posted April 5, 2008 Author Share Posted April 5, 2008 Also, How do I escape a variable? Link to comment https://forums.phpfreaks.com/topic/99707-solved-using-php-to-output-executable-php/#findComment-510084 Share on other sites More sharing options...
elite_prodigy Posted April 5, 2008 Author Share Posted April 5, 2008 [ <?php $page_home = " <?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/>\"; } ?> "; ?> The above code is outputting: <?php = mysql_connect("*******", "*******", "*******") or die(mysql_error()); mysql_select_db("expose_expose",) 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: <?php $conn = mysql_connect("localhost", "expose_expose", "spartan") 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/>\"; } ?> Link to comment https://forums.phpfreaks.com/topic/99707-solved-using-php-to-output-executable-php/#findComment-510103 Share on other sites More sharing options...
elite_prodigy Posted April 5, 2008 Author Share Posted April 5, 2008 I fixed it. It now outputs properly, I just contatenated the $ and the variable and added a tripple slash when I needed an escaped slash in my output. <?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); ?> Link to comment https://forums.phpfreaks.com/topic/99707-solved-using-php-to-output-executable-php/#findComment-510114 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.