PHP生成便于打印的网页
要生成便于打印的网页,需要我们做哪些工作呢?这主要取决于你的网站特点,和你想要生成的版式特征,不过有一些基本处理需要完成:
1、 页宽——生成页面的宽度必须限制,要打印A4的纸,大约网页要在630像素宽。
2、 页面背景色——为了美观,很多网页使用了不同的背景色和背景图片,但是作为要打印的网页,最合适效果的还是白底黑字为好。
3、 广告条——移除页面上的广告
4、 表格的背景色——我们经常在表格中用颜色来强调信息和标题,这些也必须移除。
5、 链接——页面中的超链接也必须改变以使URL可见,例如:GBDirect应显示为GBDirect (http://www.gbdirect.co.uk/)
6、 菜单——菜单是最难被禁止的,然而如果你的页面是使用模板来构建的话,那么最简单的方法是换用便于打印的没有菜单的模板。
这些生成便于打印页面的所有方法,都是非常简单的,需要实现的时候你可以被下面的代码放到网页中:
//从环境变量中得到文件的相对路径
$page=substr($SCRipT_NAME,1);
// 显示一个图标并连接到PRinter Friendly Pages
// 便于打印页面的生成程序pfp.php
?>
;

Printer Friendly Version
把当前页面的名称传递到pfp.php程序中,这个程序使用PHP的“file”函数把页面作为一个字符串来处理。当这个页面被载入的时候,程序就可以增加、改写或删除HTML片段。
ereg('^.*/',$SCRIPT_FILENAME,$tmp);
$page_path = substr($tmp[0],0,-1);
?>
// check if the filename for the page exists if (!file_exists("$page.inc")) { echo "Error - The page =$page?>". "does not exist on this site."; } else { // 得到页面的内容并把它放到一个字符串中 $fcontents = join('', file("$page.inc")); // 忽略颜色属性,转换以’ignore’替代’color’ $fcontents = ereg_replace('color','ignore',$fcontents); // 去除超链接中的 “_blank” $fcontents = ereg_replace('target=\"_blank\"','',$fcontents); // 替换标记 $fcontents = ereg_replace('','',$fcontents); // 显示URL的绝对地址 $fcontents = ereg_replace(']*>;([^]*)', '\\2(\\1)',$fcontents); // 把相对链接转为绝对链接 $fcontents = ereg_replace( ']*>([^]*)', "\\2(http://$HTTP_HOST/\\1)";, $fcontents); // 背景颜色改回白色 $fcontents = ereg_replace(' // if any markers left restore link end element $fcontents = ereg_replace('','',$fcontents); // 输出页面 echo $fcontents; } ?> |
include("$page_path/footer.inc"); ?> |
这样便于打印的页面就生成了,希望对大家能有帮助。
(译自PHPBulider/Mark Spink)

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio

In this article, we're going to explore the notification system in the Laravel web framework. The notification system in Laravel allows you to send notifications to users over different channels. Today, we'll discuss how you can send notifications ov
