Hello, I am trying to create a page on my website that dynamically extracts all of the contents in the body of a certain page which is defined in the URL: For example: http://www.domain.com/print.php?page=index.htm HTML: Of course, the 'page=' variable would change from page to page... Here is the php I have so far: <?php ereg("^.*/",$SCRIPT_FILENAME,$tmp); $page_path = substr($tmp[0],0,-1); ?> <html> <head> <base href="http://www.domain.com"> <meta name="robots" content="no index, no follow"> <title>Printer Friendly Page</title> </head> <body> <?php // check if the filename for the page exists if (!file_exists($_GET["page"])) { echo "<strong>We're sorry... we could not find that page</strong>"; } else { // get the page content and place in a string $fcontents = join("", file($_GET["page"])); $split = explode("<body>", $fcontents); $split2 = explode("</body>", $split[1]); $fcontents = $split2[0]; // convert color attribute to ignore and bgcolor to bgignore // this silently disables all color $fcontents = ereg_replace("color","ignore",$fcontents); // remove the target to a blank window attribute in links $fcontents = ereg_replace("target=\"_blank\"","",$fcontents); // replace the link end element with a single character marker $fcontents = ereg_replace("</a>","¬",$fcontents); // if any markers left restore link end element $fcontents = ereg_replace("¬","</a>",$fcontents); // finally print the page echo $fcontents; } ?> </body> </html> PHP: However, print.php just appears blank, and I don't know why. If anyone can spot an obvious (or not so obvious) error, that would be great. Thanks, SWagner
Try putting error_reporting(E_ALL) at the top of your script and run again. If that fails try running 'php -l <script name>.php' at a shell if you have access.
Which script do you mean? The one before the <html> tag, or the one inside the <body>? Also, is 'error_reporting(E_ALL)' all I need, or is there another function that is needed?
I want the user to see what the printer version looks like. I have tried the css media="print" attribute before, but people don't like printing such a colorful page because of the amount of ink it will take. They don't know that it will print other than what they see. They need something they can look at -- the print.php page... Also, can anyone help me out with this: $fcontents = file_get_contents($_GET['page']); $split = explode('<body>', $fcontents); $split2 = explode('</body>', $split[0]); $fcontents = $split2[0]; PHP: It is supposed to take the contents of just the <body> tag, but it gives me the entire page code... what should I change?
It looks $split2 is using the first cell from the $split array, which will be everything above the <body> tag. It doesn't include the content. The content would be in $split[1]. Also, this won't work if there are any attributes in the body tag. Try this: $fcontents = file_get_contents($_GET['page']); $split = explode('<body>', $fcontents); $split2 = explode('</body>', $split[1]); $fcontents = $split2[0]; Code (markup):
A php stylesheet switcher might be a good solution if you are not set on your current path. Printer friendly page link loads the media='print' stylesheet
I tried that... It gave me this error/notice: Notice: Undefined offset: 1 in /opt/www/courses2-port80/wagnerlab/print.php on line 25 Code (markup): Any suggestions?