Computing.Net > Forums > Web Development > PHP return section of string

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

PHP return section of string

Reply to Message Icon

Name: jake1025
Date: July 16, 2005 at 15:20:46 Pacific
OS: xp home
CPU/Ram: 800/256
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: Michael J (by mjdamato)
Date: July 16, 2005 at 17:29:09 Pacific
Reply:

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.


0

Response Number 2
Name: jake1025
Date: July 16, 2005 at 22:42:18 Pacific
Reply:

hey thanks i guess that method would be better


0

Response Number 3
Name: jam14online
Date: July 17, 2005 at 09:31:58 Pacific
Reply:

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; }


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


readdir PHP Web Database Search Help



Post Locked

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


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: PHP return section of string

php section disappears www.computing.net/answers/webdevel/php-section-disappears/2953.html

PHP to remove chunk of string www.computing.net/answers/webdevel/php-to-remove-chunk-of-string/3694.html

php calculation of dates www.computing.net/answers/webdevel/php-calculation-of-dates/3944.html