search
Homephp教程php手册用php把现有动态新闻页面改成静态页的方案

动态|静态|页面

请问,当我浏览某个网页时,我想在服务器的某个路径下生成对应的静态网页,以方便调用,该怎么处理比较好?
我的程序以前写的,没有这个功能.因此我想有没有比较好的在不大量改动到原程序的情况下实现该功能.


回复人:arcow(冲星) ( 五级(中级)) 信誉:100     2006-2-28 18:02:45

比如你的动态显示页面为

display.php?id=1

的话

你可以在diplay里判断一下是否在对应目录存在对应id的文件名(这里假设文件为id号+html即1.html,2.html,...)
你判断 $id."html"这个文件是否存在于服务器,如果存在就直接跳转到这个页面,要是不存在的话就创建(建义用一个函数来创建,这样对页面改动不大,比如createHTML($_GET['id']),至于这个函数怎么写,我想你应该知道)然后再跳转

-------------------------------------------------

回复人:ice_berg16(寻梦的稻草人) ( 三星(高级)) 信誉:125     2006-2-28 21:33:13

假设你显示文章的页面为
showNews.php?id=34
那么可以这么做
ob_start();
//你的正常程序代码
$html=ob_get_contents();
ob_end_clean();
$fp=fopen($_GET['id'].".htm", "w");
fwrite($fp, $html);
fclose($fp);



Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.