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

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

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

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

React combines JSX and HTML to improve user experience. 1) JSX embeds HTML to make development more intuitive. 2) The virtual DOM mechanism optimizes performance and reduces DOM operations. 3) Component-based management UI to improve maintainability. 4) State management and event processing enhance interactivity.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

In PHP8, match expressions are a new control structure that returns different results based on the value of the expression. 1) It is similar to a switch statement, but returns a value instead of an execution statement block. 2) The match expression is strictly compared (===), which improves security. 3) It avoids possible break omissions in switch statements and enhances the simplicity and readability of the code.
