Location: PHPKode > projects > Printer-friendly Version > printer-friendly-version/pfv.php
<?php

/*
You can do whatever you like with this script.  It's simple, but extremely useful if you're a programming newbiw.

This script is designed to allow someone to print just the content on a page without all the navigation elements.  It looks for two comments tags in your HTML page:

<!-- CONTENT -->     and     <!-- /CONTENT -->

Anything in between these two comment tags will be returned to the browser.

The script will also print the address of the original content page at the bottom of the printer-friendly page.  If you don't want it, remove the line '<br clear="all"><em>'.$HTTP_REFERER.'</em>'



Step 1.  Save this script in a common area on your site.  It does not have to be in your cgi-bin since it is not a cgi script, and you do not have to change its permissions.

Step 2.  Replace the comments below in the script with your information.

Step 3.  Open your HTML page and insert  <!-- CONTENT -->     and     <!-- /CONTENT -->  around your main content.

Step 4.  Outside of the  <!-- CONTENT -->     and     <!-- /CONTENT -->  tags, add a link to this script, like:

<a href="pfv.php">Printer-friendly version</a>

If you want, you can add a small printer-looking icon in your link.  You can find them lots of places online, like Mapquest.

That's it!
*/  

$fd= fread(fopen($HTTP_REFERER, "r"), 100000);  

if ($fd)  
        {  
    $start= strpos($fd, "<!-- CONTENT -->");  
    $finish= strpos($fd, "<!-- /CONTENT -->");  
    $length= $finish-$start;  
    $code=Substr($fd, $start, $length);  
    }  


echo '<html>
<head>
	<title>/* enter a generic title for your site, which will appear in the title bar of the browser window */</title>
</head>
<body leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0">
'.$code.'
<br clear="all"><em>'.$HTTP_REFERER.'</em>
</body>
</html>';  
?>
Return current item: Printer-friendly Version