php列印網頁的代碼舉例來說

來源:互聯網
上載者:User
php列印網頁的代碼舉例
本文出處參考:http://www.jbxue.com/article/6793.html
為大家介紹一個可以產生方便列印的頁面的php代碼,很多新聞網站都有這個功能,產生的頁面簡潔大方,去掉了部分多餘的元素,整個頁面只包括標題、發布時間、內容等主要元素。這個不同於window.print()的功能哦。

具體實現代碼如下:
">;列印本頁


把當前頁面的名稱傳遞到pfp.php程式中,這個程式使用PHP的“file”函數把頁面作為一個字串來處理。當這個頁面被載入的時候,程式就可以增加、改寫或刪除HTML片段。
Printer Friendly Page
Error - The 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('

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.