PHP generates HTML static pages_PHP tutorial
从PHP生成HTML静态页面并存储到以年份和月份为名称创建的目录。
读取全部数据批量生成,全部生成后弹出提示。
可指定批次生成数量,建议不超过800,否则执行速度会有问题。
为jbxue.com网站功能而开发,代码为本人原创,生成速度一般。
(出于众所周知的原因,涉及到数据库的数据字段名称做了改动,并且为了代码明晰去掉了参数过滤的部分)
说明:原动态地址为 moban.php?id=1 ,生成后地址为 html/200808/sell_1.html 。page.php为分页程序,本博客中有发布。
页面使用方式,将本代码保存为make.php,使用方法为浏览器访问 make.php?t=数量&pg=页面;例如 make.php?t=300&pg=2,即每次生成300条数据,从数据列表第2页开始生成,即跳过前面300条。如果不加任何参数,直接访问make.php,则默认每次生成200条,从第一页开始生成。
例子:
Php代码- if($_GET[pg]==''){
- $aa=1;
- }else{
- $aa=$_GET[pg];
- }
- include("admin/conn.php");
- require_once("page.php");
- $result=mysql_query("select * from 2carsell ");
- $totle=mysql_num_rows($result);
- $pagelist = $_GET[t];
- if($_GET[t]==''){
- $pagelist='200';
- }else{
- $pagelist=$_GET[t];
- }
- $pager = new Pager($totle,$pagelist);
- $datastat=" 共 ".$pager->countall." 条,每次生成 ".$pager->countlist." 条,共需生成 ".$pager->page." 次";//数据统计
- $bb=$pager->page;
- $pagenav=$pager->backstr.$pager->thestr.$pager->nextstr;
- $limitFrom = $pagelist*($pager->pg-1);
- $result=mysql_query("select * from 2carsell ORDER BY id DESC limit $limitFrom,$pagelist");
- ?>
- "font-size:14px;">第 echo $aa?> 次页面生成中.. echo $datastat?>
- //php生成静态页面
- // www.jbxue.com
- print "
; - while($datauser=mysql_fetch_array($result)){
- $iid=$datauser[id];
- $html = file_get_contents("/moban.php?id=".$iid."");
- $sql="select * from 2carsell where id=$iid";
- $data=mysql_fetch_array(mysql_query($sql));
- $path=date("Ym",$data[PutDate]);
- $testdir="html/".$path;
- if(file_exists ($testdir)):
- else:
- mkdir ($testdir, 0777);
- echo "目录".$testdir."创建成功!
"; - endif;
- $filename = "html/$path/sell_$iid.html";
- // 使用写入模式打开$filename
- if (!$handle = fopen($filename, 'w')) {
- print "不能打开文件 $filename";
- exit;
- }
- if (is_writable($filename)) {
- // 将$html写入到我们打开的文件中。
- if (!fwrite($handle, $html)) {
- print "不能写入到文件 $filename";
- exit;
- }
- print "文件 $filename 更新成功!\n\r";
- fclose($handle);
- } else {
- print "文件 $filename 不可写";
- }
- ?>
- }?>
- "font-size=12px"> echo $datastat." "?>
- $aa=$aa+1;
- if($aa>$bb){
- echo 'Congratulations, all pages have been generated! ';
- echo "<script>alert('All documents generated/updated!')</script>";
- }else{
- echo "<Script> window.location='make.php?t=$pagelist&pg=$aa'; </script>";
- }
- ?>

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



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Validator can be created by adding the following two lines in the controller.

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP is an open source MVC framework. It makes developing, deploying and maintaining applications much easier. CakePHP has a number of libraries to reduce the overload of most common tasks.

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an
