Jump to content

how to save html output code from php script


southfloridarentalz

Recommended Posts

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>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.