Zend - The PHP Company




Text

Add Code


PHPrint - "Print this Page" script  

Type: application
Added by: garrotte
Entered: 31/07/2002
Last modified: 08/12/2001
Rating: ***** (3 votes)
Views: 26648
Printer friendly pages from anywhere on a website. This dynamic "Print This Page" script works right out of the box - cut and paste. Has the option to leave images in the new print friendly page if required. Just link to this script, and it will give a printer friendly version of any page, whether it's a PHP, ASP, CGI, or HTML page. Comes with a Cascading StyleSheet for further control of your print-friendly pages.


<?php 

/*PHPrint - Save this as file: phprint.php
Make any Page Printer Friendly!
Copyright by MikeNew.Net
************
Legal: MikeNew.Net is not responsible for any damages caused
by use of this script. (Not that it will, probably. Never has.)
This script will make your pages printer friendly. 
Optionally, it will strip images as well. (Instructions for that below)

// After installation, you can remove text from here down to the next: 8< ---->
// Back up/copy this file first.

1. Save this script in the root of the site for simplicity.
2. Place <!-- startprint --> somewhere in your HTML page where you consider 
it to be the start of printer friendly content, and <!-- stopprint --> goes at the end
of that same content.

3. You place a link to phprint.php anywhere on the HTML page (preferably outside the printed content,
like this: <a href="/phprint.php">Print this page</a>
- or however you like, just as long as you link to this script.

*/ 

//Do you want to strip images from the printable output?
// If no, change to "no". Otherwise, images are stripped by default.
$stripImages "no";
// If you've already tested, you can remove the text from here up to the other: 8< ---->

// That's it! No need to go below here. Upload it and test.

$startingpoint "<!-- startprint -->";
$endingpoint "<!-- stopprint -->";

$read fopen($HTTP_REFERER"rb");
$value "";
while(!
feof($read)){
$value .= fread($read4096); 
}
fclose($read);
$startstrpos($value"$startingpoint"); 
$finishstrpos($value"$endingpoint"); 
$length$finish-$start;
$value=substr($value$start$length);

function 
i_denude($variable)
{
return(
eregi_replace("<img src=[^>]*>"""$variable));
}

function 
i_denudef($variable)
{
return(
eregi_replace("<font[^>]*>"""$variable));
}

$PHPrint = ("$value"); 

if (
$stripImages == "yes") {
$PHPrint i_denude("$PHPrint");
}


$PHPrint i_denudef("$PHPrint");
$PHPrint str_replace"</font>"""$PHPrint );
//

echo $PHPrint
// Next line mandatory. Please don't remove. It's honest exchange instead of paying for this script. Thanks! :)
echo "<br><a href="http://www.mikenew.net/"><font size="1">PHPrint Script</font></a>";
echo "<br/><font size="1">$HTTP_REFERER</font><br/><br/>This page printed from: $HTTP_REFERER";
flush (); //force 
?>


Usage Example


See the example


Rate This Script





Search



This Category All Categories