southfloridarentalz Posted December 29, 2010 Share Posted December 29, 2010 I found this site: http://www.wallpaperama.com/forums/how-to-save-html-output-code-from-php-script-t6898.html it demonstrates how to save html output code from php script. here is an example: http://ads4agents.com/date.php I cant get it to work on my site...where is the correct place ad these: ob_start(); $HtmlCode= ob_get_contents(); ob_end_flush(); How can I get this to work in my php? view_ad.php <html> <body> <center> <br/> <h1>Apartment Reference #: <?php echo $_POST["reference"]; ?><br /></h1> <br/> <?php echo $_POST["application"]; ?>, <?php echo $_POST["deposit"]; ?><br /> <?php echo $_POST["pets"]; ?><br /> <br/> <?php echo $_POST["community"]; ?><br /> <?php echo $_POST["interior"]; ?><br /> <?php echo $_POST["amenities"]; ?><br /> <br/> <?php echo $_POST["contact"]; ?><br /> <a href="<?php echo $_POST['website'] ?>"><?php echo $_POST['website'];?></a><br/> <br/> <br/> <br/> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/222954-how-to-save-html-output-code-from-php-script/ Share on other sites More sharing options...
trq Posted December 29, 2010 Share Posted December 29, 2010 ob_start() goes before any output, and the rest goes after it. Quote Link to comment https://forums.phpfreaks.com/topic/222954-how-to-save-html-output-code-from-php-script/#findComment-1152792 Share on other sites More sharing options...
southfloridarentalz Posted December 29, 2010 Author Share Posted December 29, 2010 can you copy and past the correct code? I am a noob Quote Link to comment https://forums.phpfreaks.com/topic/222954-how-to-save-html-output-code-from-php-script/#findComment-1152794 Share on other sites More sharing options...
PHPTOM Posted December 29, 2010 Share Posted December 29, 2010 <?php ob_start(); ?> <html> <body> <center> <br/> <h1>Apartment Reference #: <?php echo $_POST["reference"]; ?><br /></h1> <br/> <?php echo $_POST["application"]; ?>, <?php echo $_POST["deposit"]; ?><br /> <?php echo $_POST["pets"]; ?><br /> <br/> <?php echo $_POST["community"]; ?><br /> <?php echo $_POST["interior"]; ?><br /> <?php echo $_POST["amenities"]; ?><br /> <br/> <?php echo $_POST["contact"]; ?><br /> <a href="<?php echo $_POST['website'] ?>"><?php echo $_POST['website'];?></a><br/> <br/> <br/> <br/> </body> <?PHP $HtmlCode= ob_get_contents(); ob_end_flush(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/222954-how-to-save-html-output-code-from-php-script/#findComment-1152795 Share on other sites More sharing options...
southfloridarentalz Posted December 29, 2010 Author Share Posted December 29, 2010 i have added your script, but I am not seeing any changes to the output. In this example: http://ads4agents.com/date.php you can see the screen is seperated, with the HTML displayed below. My site does not display this html. Quote Link to comment https://forums.phpfreaks.com/topic/222954-how-to-save-html-output-code-from-php-script/#findComment-1152800 Share on other sites More sharing options...
PHPTOM Posted December 29, 2010 Share Posted December 29, 2010 What are your motives for doing this? I don't get what you are trying to achieve by using output buffering. If you want to display the code just put: <html> <body> <center> <br/> <h1>Apartment Reference #: <?php echo $_POST["reference"]; ?><br /></h1> <br/> <?php echo $_POST["application"]; ?>, <?php echo $_POST["deposit"]; ?><br /> <?php echo $_POST["pets"]; ?><br /> <br/> <?php echo $_POST["community"]; ?><br /> <?php echo $_POST["interior"]; ?><br /> <?php echo $_POST["amenities"]; ?><br /> <br/> <?php echo $_POST["contact"]; ?><br /> <a href="<?php echo $_POST['website'] ?>"><?php echo $_POST['website'];?></a><br/> <br/> <br/> <br/> </body> </html> into a blank php file and it will display Quote Link to comment https://forums.phpfreaks.com/topic/222954-how-to-save-html-output-code-from-php-script/#findComment-1152802 Share on other sites More sharing options...
southfloridarentalz Posted December 30, 2010 Author Share Posted December 30, 2010 Look at this link: http://www.ads4agents.com/date.php This is what I want to accomplish for my php. It displays the PHP final product on the top and the source code on the bottom. This way the source code can be copied and pasted into other sites like that accept html. Understand? Quote Link to comment https://forums.phpfreaks.com/topic/222954-how-to-save-html-output-code-from-php-script/#findComment-1152806 Share on other sites More sharing options...
southfloridarentalz Posted December 30, 2010 Author Share Posted December 30, 2010 Is there any PHP pros that can help me? Quote Link to comment https://forums.phpfreaks.com/topic/222954-how-to-save-html-output-code-from-php-script/#findComment-1152819 Share on other sites More sharing options...
southfloridarentalz Posted December 30, 2010 Author Share Posted December 30, 2010 Also found this: http://www.daniweb.com/forums/thread68106.html How can I do this? Quote Link to comment https://forums.phpfreaks.com/topic/222954-how-to-save-html-output-code-from-php-script/#findComment-1152821 Share on other sites More sharing options...
Psycho Posted December 30, 2010 Share Posted December 30, 2010 Here is a very simple example: <?php //Turn on output buffering ob_start(); //Create/Output the BODY of the HTML document $datetime = date('m-d-Y H:m:i'); echo "<h2>Today is: {$datetime}</h2>\n"; echo "More content goes here"; //Save the body to a variable $body = ob_get_contents(); //Create an escaped version of the body $body_code = nl2br(htmlentities($body)); //Clear the content of the output buffer ob_end_clean(); //Output the results of the body and the code ?> <html> <head> <title>Test Page</title> <head> <body> <?php echo $body; ?> <hr> This is the value of $body: <br><br> <?php echo $body_code; ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/222954-how-to-save-html-output-code-from-php-script/#findComment-1152828 Share on other sites More sharing options...
southfloridarentalz Posted December 30, 2010 Author Share Posted December 30, 2010 Can you apply your method to this script: <html> <body> <center> <br/> <h1>Apartment Reference #: <?php echo $_POST["reference"]; ?><br /></h1> <br/> <?php echo $_POST["application"]; ?>, <?php echo $_POST["deposit"]; ?><br /> <?php echo $_POST["pets"]; ?><br /> <br/> <?php echo $_POST["community"]; ?><br /> <?php echo $_POST["interior"]; ?><br /> <?php echo $_POST["amenities"]; ?><br /> <br/> <?php echo $_POST["contact"]; ?><br /> <a href="<?php echo $_POST['website'] ?>"><?php echo $_POST['website'];?></a><br/> <br/> <br/> <br/> </body> </html> Here is a very simple example: <?php //Turn on output buffering ob_start(); //Create/Output the BODY of the HTML document $datetime = date('m-d-Y H:m:i'); echo "<h2>Today is: {$datetime}</h2>\n"; echo "More content goes here"; //Save the body to a variable $body = ob_get_contents(); //Create an escaped version of the body $body_code = nl2br(htmlentities($body)); //Clear the content of the output buffer ob_end_clean(); //Output the results of the body and the code ?> <html> <head> <title>Test Page</title> <head> <body> <?php echo $body; ?> <hr> This is the value of $body: <br><br> <?php echo $body_code; ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/222954-how-to-save-html-output-code-from-php-script/#findComment-1152853 Share on other sites More sharing options...
trq Posted December 30, 2010 Share Posted December 30, 2010 Its not rocket science. ob_start() goes before any output, and the rest goes after it. If you cannot understand that I would seriously reconsider spending your time learning php. Quote Link to comment https://forums.phpfreaks.com/topic/222954-how-to-save-html-output-code-from-php-script/#findComment-1152857 Share on other sites More sharing options...
southfloridarentalz Posted December 30, 2010 Author Share Posted December 30, 2010 I understand it. It is not working properly. I didn't know you working with the php cool police now...jerkie Quote Link to comment https://forums.phpfreaks.com/topic/222954-how-to-save-html-output-code-from-php-script/#findComment-1152869 Share on other sites More sharing options...
trq Posted December 30, 2010 Share Posted December 30, 2010 I understand it. It is not working properly. Then post your code and an explanation of your issue. I didn't know you working with the php cool police now...jerkie Seriously, I'm not sure it can be explained any simpler. Quote Link to comment https://forums.phpfreaks.com/topic/222954-how-to-save-html-output-code-from-php-script/#findComment-1152880 Share on other sites More sharing options...
fortnox007 Posted December 30, 2010 Share Posted December 30, 2010 don't you just accidentally mean the pre tags <pre></pre> http://www.w3schools.com/TAGS/tag_pre.asp Quote Link to comment https://forums.phpfreaks.com/topic/222954-how-to-save-html-output-code-from-php-script/#findComment-1153165 Share on other sites More sharing options...
Psycho Posted December 30, 2010 Share Posted December 30, 2010 don't you just accidentally mean the pre tags <pre></pre> http://www.w3schools.com/TAGS/tag_pre.asp PRE tags only preserve spaces and line breaks and display the font in a fixed-width style. If you have any "code" in the content it can still be processed by the browser. The example I used has nl2br() to convert the line breaks to BR tags Quote Link to comment https://forums.phpfreaks.com/topic/222954-how-to-save-html-output-code-from-php-script/#findComment-1153178 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.