Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
im making an app in php that outputs a "printer friendly" version of any specified page. all of the pages in my site are generated from a central "dreamweaver tempelate file" which consists of items like navigation bars, logos, etc. and has a seperate place in the body where you can add page contents. this makes it easy to make changes to the site layout without editing each individual file.
anyway what i want to do is have php strip all of the template generated data from a specified page and only return the "unique contents", thus making it "printer friendly".
example page to be parsed:
<head>...</head><body>...
.................
<-- beginEdit -->
(printer friendly content that needs to be outputed by php)
<-- endEdit -->
..........
...</body>example php code:
<?
if(isset($_GET['file'])){
$fp=fopen($_GET['file'], "r");
$str=fread($fp, filesize($_GET['file']));
/*
what function could i put here to remove everything before , and put everything else into the variable $str?
*/print $str;
}
?>thanks for any help
-jake

Jake, there is an easier way to do what you want without any programming whatsoever.
There is a style property called "@media". With it you can specify the style property for different elements to be differnt depending upon the medis type. When viewed on screen the media type of the page is 'screen', but when you print the page the media type is 'print'.
So, in your example you can make the display property for your navigation bar be 'in-line' when the media type is screen and 'none' when the media type is print. This will hide the navigation section when printing the page. One you set up your template correctly, your visitors can print any page and only the content you specify will be printed.
Just do a Google search for "css @media" for more info.

I was going to suggest the exact same method, so here's the code I'd recommend using:
<link href="default.css" media="projection, screen, tv" rel="stylesheet" type="text/css"/>
<link href="print.css" media="print" rel="stylesheet" type="text/css"/>If you put that in the <head> of your pages, you simply have the filed named "default.css" as your normal stylesheet. When you go to print (or print preview) the page, the browser will use the "print.css" stylesheet.
If you had a navigation section, that is usually worthless when you want to print, you could exclude it by giving it a unique ID and then adding "display: none" to the print.css stylesheet.
For example, if you had a <ul> with an ID of "menu", you would add this to print.css:
ul#menu { display: none; }

![]() |
readdir PHP
|
Web Database Search Help
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |