PHP's code for printing Web pages for example

Source: Internet
Author: User
Example code for PHP-printed web pages
Reference to this article: http://www.jbxue.com/article/6793.html
For everyone to introduce a convenient printing page of PHP code, many news sites have this feature, the resulting page is simple and generous, remove some of the extra elements, the entire page only includes the title, release time, content and other main elements. This is different from the Window.print () function Oh.

The specific implementation code is as follows:
 
  ">; Print this page


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.
 
 
  
 <title>Printer Friendly Page</title>
 
Error-the page "." Does not exist in this site. ";} else{//gets the contents of the page and puts it into a string $fcontents = Join (', File ("$page. Inc"),//Ignore the color attribute, convert to ' ignore ' instead of ' color ' $fcontents = Ereg_ Replace (' color ', ' ignore ', $fcontents);//Remove "_blank" in the hyperlink $fcontents = ereg_replace (' target=\ "_blank\" ', ' ", $ fcontents);//replace Mark $fcontents = Ereg_replace (",", $fcontents);//Displays the absolute address of the URL $fcontents = ereg_replace (']*>;([^]*] ' , '\\2(\\1)', $fcontents);//Convert relative link to absolute link $fcontents = ereg_replace (']*> ([^]*) ', "\\2 (http://$HTTP _host/\\1)";, $fcontents);//Background color change back to white $fcontents = ereg_replace ('

  • 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.