Jump to content

[SOLVED] Using PHP to output executable PHP.


elite_prodigy

Recommended Posts

$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.

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?

[


<?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/>\";

}


?>

 

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);

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.