PDA

View Full Version : Printer Friendly Version


SDP2006
06-26-2003, 03:58 AM
Is there a script that would take some text and generate it into another document (a.k.a the printer friendly version) ??



Thanks

duniyadnd
06-26-2003, 01:16 PM
You can use regexp and collect all the information from the page and remove all the "/<img.*?>/i" tags.

so you would pop up a new page, which collects the information from a referrer, and the script would include



$pattern = "/<img.*?>/i";
$replacement = "";
$page = $_SERVER['HTTP_REFERER'];

$page = preg_replace($pattern, $replacement, $page);
echo $page;



I didn't test the code out, but it goes something like that.

Hope that helped..

SDP2006
06-26-2003, 02:38 PM
Well, it is actually a sports schedule for a school in a table that the web manager asked me to see if I could make the schedule printer friendly. The schedule is on a page with the team roster, pictures, awards, results, etc.

If you would like to take a look, here is the site

Click Here (http://www.pickens.k12.sc.us/liberty.hs/football.html)


Thanks

duniyadnd
06-26-2003, 02:44 PM
Even Easier...

Before your table, put a comment tag

<!--Start Table-->

After your table, put a comment tag

<!--End Table-->

Now in the PHP for printer friendly thingadabob page, you call it in as such:



$start = "<!--Start Table-->";
$end = "<!--End Table-->";
$document = "YOUR_URL_EDIT_THIS";


$open = fopen("$document", "rb"); //open the document
$retrieve = @fread($open, 200000); //read the document
if ($retrieve) //if it exists
{
$grab = eregi("$start(.*)$end", $retrieve, $data); /*go through the page*/
}//end if
echo $grab;
fclose($open);

brothercake
06-26-2003, 02:48 PM
Why use PHP? You could accomplish that with print-media CSS, and it would be much easier and more flexible.

duniyadnd
06-26-2003, 02:49 PM
PHP Forum so I answered it the PHP Way... :D

Oh, and I never did it the CSS Way.. :o

SDP2006
06-26-2003, 03:01 PM
Where do I put that code? I saved it as pf.php and linked it "Printer Friendly" from there.

duniyadnd
06-26-2003, 03:03 PM
You put the code in pf.php.

<html>
<body>
<?

Code goes here

?>


</body>
</html>

SDP2006
06-26-2003, 03:06 PM
OK. There was no error that time, but the page was blank.

This is the location of it :
http://www.newlifeonline.net/calendars/june_calendar.htm

I am testing it out on my churches calendar.

duniyadnd
06-26-2003, 03:07 PM
The casing and spacing should be the same for both.

ie. <!--Begin Table--> is NOT the same as <!--BEGIN TABLE-->

SDP2006
06-26-2003, 03:17 PM
OK, Now it displayed "6242"

duniyadnd
06-26-2003, 03:20 PM
and that's because i'm an idiot...

sorry,

echo $data[1];

instead of

echo $grab;

SDP2006
06-26-2003, 03:21 PM
Your not an idiot!

Works like a charm!