swagner
10-14-2007, 10:45 AM
Hello,
I recently found a great code to create a print.php page that dynamically extracts all the contents of the page that is specified in the url:
For example:
http://www.domain.com/print.php?page=index.htm
Of course, the 'page=' variable would change from page to page...
Here is the code I found:
<?
ereg('^.*/',$SCRIPT_FILENAME,$tmp);
$page_path = substr($tmp[0],0,-1);
?>
<html>
<head>
<base href="http://<? echo $HTTP_HOST ?>/">
<meta name="robots" content="no index, no follow">
<title>Printer Friendly Page</title>
</head>
<body bgcolor="white">
<font face="Arial,Helvetica">
<table border="0" cellpadding="5" cellspacing="0" width="630" >
<tr>
<td valign="top">
<?
// check if the filename for the page exists
if (!file_exists("$page"))
{
echo "<strong>Error - The page <?=$page?>".
"does not exist on this site.</strong>";
}
else
{
// get the page content and place in a string
$fcontents = join('', file("$page"));
// 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);
// show links to absolute url references
$fcontents = ereg_replace('<a[^h]*href="(http://[^"]*)"[^>]*>;([^¬]*)¬',
'<strong>\\2</strong><em>(\\1)</em>',$fcontents);
// show relative links with full url to home site
$fcontents = ereg_replace(
'<a[^h]*href="([^"]*)"[^>]*>([^¬]*)¬',
"<strong>\\2</strong><em>(http://$HTTP_HOST/\\1)</em>",
$fcontents);
// since my preferred background color is white I need only
// can change the body color tag back
$fcontents = ereg_replace('<body bgignore','<body bgcolor', $fcontents);
// if any markers left restore link end element
$fcontents = ereg_replace('¬','</a>',$fcontents);
// finally print the page
echo $fcontents;
}
?>
</td>
</tr>
</table>
</font>
</body>
</html>
(Source: http://www.aria.uklinux.net/pfp.php)
Now, I tried this on my server, but every time, it gives me the error message (see code above). I do not know why. Any help would be great.
Thanks,
SWagner
I recently found a great code to create a print.php page that dynamically extracts all the contents of the page that is specified in the url:
For example:
http://www.domain.com/print.php?page=index.htm
Of course, the 'page=' variable would change from page to page...
Here is the code I found:
<?
ereg('^.*/',$SCRIPT_FILENAME,$tmp);
$page_path = substr($tmp[0],0,-1);
?>
<html>
<head>
<base href="http://<? echo $HTTP_HOST ?>/">
<meta name="robots" content="no index, no follow">
<title>Printer Friendly Page</title>
</head>
<body bgcolor="white">
<font face="Arial,Helvetica">
<table border="0" cellpadding="5" cellspacing="0" width="630" >
<tr>
<td valign="top">
<?
// check if the filename for the page exists
if (!file_exists("$page"))
{
echo "<strong>Error - The page <?=$page?>".
"does not exist on this site.</strong>";
}
else
{
// get the page content and place in a string
$fcontents = join('', file("$page"));
// 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);
// show links to absolute url references
$fcontents = ereg_replace('<a[^h]*href="(http://[^"]*)"[^>]*>;([^¬]*)¬',
'<strong>\\2</strong><em>(\\1)</em>',$fcontents);
// show relative links with full url to home site
$fcontents = ereg_replace(
'<a[^h]*href="([^"]*)"[^>]*>([^¬]*)¬',
"<strong>\\2</strong><em>(http://$HTTP_HOST/\\1)</em>",
$fcontents);
// since my preferred background color is white I need only
// can change the body color tag back
$fcontents = ereg_replace('<body bgignore','<body bgcolor', $fcontents);
// if any markers left restore link end element
$fcontents = ereg_replace('¬','</a>',$fcontents);
// finally print the page
echo $fcontents;
}
?>
</td>
</tr>
</table>
</font>
</body>
</html>
(Source: http://www.aria.uklinux.net/pfp.php)
Now, I tried this on my server, but every time, it gives me the error message (see code above). I do not know why. Any help would be great.
Thanks,
SWagner