Ways to generate Web pages that are easy to print with PHP

Source: Internet
Author: User
This article mainly introduces the use of PHP to generate easy to print web pages, has a certain reference value, and now share to everyone, the need for friends can refer to

Many news and information sites provide a way to generate pages that are easy to print, and the layout of the resulting pages is more conducive to the printout of the printer, which makes it easier for us to print the content we need directly from the Web page without having to worry about formatting or pasting it into a text editor to re-typeset. However, I do not see how many sites explain how these are implemented in detail, here I provide a small piece of code-PHP to generate easy to print Web page is not as difficult as imagined, I hope to be helpful.
What do we need to do to generate pages that are easy to print? This depends on your site's characteristics, and the layout features you want to generate, but there are some basic processing needs to be done:
1, page width-the width of the generated page must be limited, to print A4 of paper, about the page to be 630 pixels wide.
2, page background color-for beautiful, a lot of web pages use different background color and background image, but as the page to be printed, the most appropriate effect or white black word for good.
3. Banner--Remove the ads on the page
4, the background color of the table-we often use color in the table to emphasize the information and the title, which must also be removed.
5, Link--The hyperlink in the page must also be changed to make the URL visible, for example: <a href=http://www.gbdirect.co.uk/>GBDirect</a> should be displayed as Gbdirect (/HTTP// www.gbdirect.co.uk/)
6, Menu-menu is the most difficult to be banned, however, if your page is built using a template, then the simplest way is to easily print the template without a menu.
These builds are easy to print all the way to the page, it is very easy to implement when you can be placed in the following code on the page:

<? Gets the relative path of the file from the environment variable $page =substr ($SCRIPT _name,1); Displays an icon and connects to printer friendly pages///easy to print page builder pfp.php?> <a href= "pfp.php?page=<?= $page?>" >;   <font face= "Arial, Helvetica" size= "2" >     Printer friendly Version   </font> </a>

Pass the name of the current page to the pfp.php program, which uses PHP's "file" function to handle the page as a string. When the page is loaded, the program can add, rewrite, or delete HTML fragments.

<?  Ereg (' ^.*/', $SCRIPT _filename, $tmp); $page _path = substr ($tmp [0],0,-1);?> 

This is a convenient way to print the page is generated, we hope to be helpful.

The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.