P-h-p技术生成静态页面的实现.docx_第1页
P-h-p技术生成静态页面的实现.docx_第2页
P-h-p技术生成静态页面的实现.docx_第3页
P-h-p技术生成静态页面的实现.docx_第4页
P-h-p技术生成静态页面的实现.docx_第5页
已阅读5页,还剩14页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

php技术生成静态页面的实现(Implementation of static page generation by PHP Technology)php技术生成静态页面的实现(Implementation of static page generation by PHP Technology) One, PHP script and dynamic page. PHP script is a server-side scripting program, which can be mixed with HTML files by embedding and other methods. It can also be used in class, function encapsulation and other forms to deal with user requests in the form of templates. In any way, the basic principle is this. The request from the client requests a page - Web server are introduced to specify the corresponding script processing - script is loaded by the server server - specified PHP parser script analytical form HTML language form - parsing HTML sentence on the way back to the browser. It is not difficult to see, after the page sent to the browser, PHP does not exist, has been transformed into HTML statement. The client requests a dynamic file, and in fact there is no real file, where the PHP corresponds to the page, and then sends it back to the browser. This page processing method is called dynamic page. Two, static page. Static page refers to the server really exists only contains HTML and JS, CSS and other clients run the script page. Its a way of dealing with it. The request from the client requests a page - WEB server to confirm and load a page - WEB server will package the page to transfer back to the browser. From this process, we compare the dynamic page, you can present. The dynamic page is required by the Web server PHP parser parsing, and often need to connect to the database, the database access operation, and then to form the HTML language information packet; and a static page, without analysis, without connecting to the database, sent directly, which can greatly reduce the server pressure, improve server load capacity, providing significant page open speed and website the overall speed of opening. However, the disadvantage is that the request can not be processed dynamically, and the file must exist on the server. Three, template and template analysis. The template has not filled the content HTML file yet. For example: Temp.html Code: Here are the quotes: Title This is a file files templets PHP processing: Here are the quotes: Templetest.php Code: $title = HP enthusiasts test template; $file = TwoMax Inter test templet, Author:Sheyi; $fp = fopen (temp.html, R); $content = FREAD ($fp, filesize (temp.html); $content = str_replace (file, $file, $content); $content = str_replace (Title, $title, $content); Echo $content; ? Template parsing process, the PHP script parsed by the results obtained by filling (content) into the template process. Template classes are usually used. Currently popular template parsing classes are phplib, Smarty, fastsmarty, and so on. The principle of template parsing is usually substitution. Some programmers are accustomed to putting judgment, loop, and other processing into template files, using analytic class processing, the typical application is block concept, simply speaking is a cycle processing. PHP script specifies the number of cycles, how to cycle, replace, etc., and then the template parsing class specific implementation of these operations. Well, compared to the static pages and dynamic pages of their respective advantages and disadvantages, and now we will talk about how to use PHP to generate static files. Static pages generated by PHP do not refer to dynamic parsing of PHP, output HTML pages, but to create HTML pages with PHP. At the same time, because of the non writable of HTML, if we create the HTML, if you want to modify, you need to delete the re generated. Of course, you can also choose regular modifications, But personally think that doing so is better than deleting the re generated faster, some gains outweigh the gains. ) Get down to business。 Used PHP file operation function of PHP FANS know, there is a file operation function fopen in PHP, namely open the file. If the file does not exist, try to create it. This is the theoretical foundation that PHP can be used to create HTML files. You can create a file whenever you have the permissions to write the folder in the HTML file, that is, permissions define 0777. For UNIX systems, the Win system does not need to be considered. Still, for example, if we modify the last sentence and specify a static file named test.html in the test directory: Code: Here are the quotes: $title = extension international test template; $file = TwoMax Inter test templet, Author:_Max MatrixTwo_Max; $fp = fopen (temp.html, R); $content = FREAD ($fp, filesize (temp.html); $content = str_replace (file, $file, $content); $content = str_replace (Title, $title, $content); Echo / / $content; $filename = test/test.html; $handle = fopen ($filename, w); / / create a file to open the file pointer. * Check if the file was created and writable * / If (. Is_writable ($filename) Die (file:.$filename.) is not writable. Please check its properties and try again; If (! Fwrite ($handle, $content) / / information will be written to the file Die (generated file .$filename. failed!); Fclose ($handle); / / close pointer Die (create file .$filename.) succeed!; ? Practical application of common problems solution reference: First, the article list problem: Create a field in the database, log file name, each generates a file, the file name will be automatically stored in the database for the recommended articles, only to the specified folder in the file storing static page. Use PHP operation processing article list, save as string, generate page replace this string. For example, in the page, the list of articles is added to the tag articletable, and in the PHP processing file: Code: Here are the quotes: $title = extension international test template; $file = TwoMax Inter test templet, Author:_Max MatrixTwo_Max; $fp = fopen (temp.html, R); $content = FREAD ($fp, filesize (temp.html); $content = str_replace (file, $file, $content); $content = str_replace (Title, $title, $content); Start / / generate a list $list =; $sql = select id, title, filename from article; $query = mysql_query ($sql); While ($result = mysql_fetch_array ($query) $list =.$resulttitle. ; $content = str_replace (articletable, $list, $content); / / end of list generation Echo / / $content; $filename = test/test.html; $handle = fopen ($filename, w); / / create a file to open the file pointer. * Check if the file was created and writable * / (if! is_writable($文件名) 死(“文件:“美元。文件名。”不可写,请检查其属性后重试”); 如果(fwrite($手柄,$content) /将信息写入文件 死(“生成文件”。$文件名。”失败”); 关闭文件(美元/关闭指针处理); 死(“创建文件”。$文件名。”成功”); , 二、分页问题。 如我们指定分页时,每页20篇。某子频道列表内文章经数据库查询为45条,则,首先我们通过查询得到如下参数:1,总页数;2,每页篇数。第二步,为($我= 0;我 allpages美元美元;i+),页面元素获取,分析,文章生成,都在此循环中执行。不同的是,死(“创建文件”。$文件名。”成功“;这句去掉,放到循环后的显示,因为该语句将中止程序执行。例: 代码: 以下是引用片段: $ FP = fopen(“温度。HTML”、“R”); $content = fread($ FP,文件大小(“温度。html”); 页=“20美元; SQL =“选择ID美元从第信道= $ channelid ”; 查询= mysql_query美元($ SQL); Num = mysql_num_rows美元($查询); allpages美元=细胞($民元/页); 为($我= 0;美元美元美元我 大致思路如此,其中如其它数据生成,数据输入输出检查,分页内容指向等可酌情在页面中加入。 在实际文章系统处理过程当中,还有许多问题有待考虑,与动态页面不同之处,需注意的地方还有很多但大致思路即是如此,其它方面可举一反三而得。 我们先回顾一些基本的概念。 一、PHP脚本与动态页面。 脚本是一种服务器端脚本程序可通过嵌入等方法与PHP,HTML文件混合,也可以类, The form of function encapsulation is used to deal with users request in the form of template. In any way, the basic principle is this. The request from the client requests a page - Web server are introduced to specify the corresponding script processing - script is loaded by the server server - specified PHP parser script analytical form HTML language form - parsing HTML sentence on the way back to the browser. It is not difficult to see, after the page sent to the browser, PHP does not exist, has been transformed into HTML statement. The client requests a dynamic file, and in fact there is no real file, where the PHP corresponds to the page, and then sends it back to the browser. This page processing method is called dynamic page. Two, static page. Static page refers to the server really exists only contains HTML and JS, CSS and other clients run the script page. Its a way of dealing with it. The request from the client requests a page - WEB server to confirm and load a page - WEB server will package the page to transfer back to the browser. From this process, we compare the dynamic page, you can present. The dynamic page is required by the Web server PHP parser parsing, and often need to connect to the database, the database access operation, and then to form the HTML language information packet; and a static page, without analysis, without connecting to the database, sent directly, which can greatly reduce the server pressure, improve server load capacity, providing significant page open speed and website the overall speed of opening. However, the disadvantage is that the request can not be processed dynamically, and the file must exist on the server. Three, template and template analysis. The template has not filled the content HTML file yet. For example: Temp.html Code: Here are the quotes: Title This is a file files templets PHP processing: Here are the quotes: Templetest.php Code: $title = HP enthusiasts test template; $file = TwoMax Inter test templet, Author:Sheyi; $fp = fopen (temp.html, R); $content = FREAD ($fp, filesize (temp.html); $content = str_replace (file, $file, $content); $content = str_replace (Title, $title, $content); Echo $content; ? Template parsing process, the PHP script parsed by the results obtained by filling (content) into the template process. Template classes are usually used. Currently popular template parsing classes are phplib, Smarty, fastsmarty, and so on. The principle of template parsing is usually substitution. Some programmers are accustomed to putting judgment, loop, and other processing into template files, using analytic class processing, the typical application is block concept, simply speaking is a cycle processing. PHP script specifies the number of cycles, how to cycle, replace, etc., and then the template parsing class specific implementation of these operations. Well, compared to the static pages and dynamic pages of their respective advantages and disadvantages, and now we will talk about how to use PHP to generate static files. Static pages generated by PHP do not refer to dynamic parsing of PHP, output HTML pages, but to create HTML pages with PHP. At the same time, because of the non writable of HTML, if we create the HTML, if you want to modify, you need to delete the re generated. (of course, you can also choose to use regular modification, but personally think that it is better to delete the re generated faster than others. ) Get down to business。 Know PHP FANS using PHP file manipulation function, There is a file operation function fopen in PHP, that is, open the file. If the file does not exist, try to create it. This is the theoretical foundation that PHP can be used to create HTML files. You can create a file whenever you have the permissions to write the folder in the HTML file, that is, permissions define 0777. For UNIX systems, the Win system does not need to be considered. Still, for example, if we modify the last sentence and specify a static file named test.html in the test directory: Code: Here are the quotes: $title = extension international test template; $file = TwoMax Inter test templet, Author:_Max MatrixTwo_Max; $fp = fopen (temp.html, R); $content = FREAD ($fp, filesize (temp.html); $content = str_replace (file, $file, $content); $content = str_replace (Title, $title, $content); Echo / / $content; $filename = test/test.html; $handle = fopen ($filename, w); / / create a file to open the file pointer. * Check if the file was created and writable * / If (. Is_writable ($filename) Die (file:.$filename.) is not writable. Please check its properties and try again; If (! Fwrite ($handle, $content) / / information will be written to the file Die (generated file .$filename. failed!); Fclose ($handle); / / close pointer Die (create file .$filename.) succeed!; ? Practical application of common problems solution reference: First, the article list problem: Create a field in the database, log file name, each generates a file, the file name will be automatically stored in the database for the recommended articles, only to the specified folder in the file storing static page. Use PHP operation processing article list, save as string, generate page replace this string. For example, in the page, the list of articles is added to the tag articletable, and in the PHP processing file: Code: Here are the quotes: $title = extension international test template; $file = TwoMax Inter test templet, Author:_Max MatrixTwo_Max; $fp = fopen (temp.html, R); $content = FREAD ($fp, filesize (temp.html); $content = str_replace (file, $file, $content); $content = str_replace (Title, $title, $content); Start / / generate a list $list =; $sql = select id, title, filename from article; $query = mysql_query ($sql); While ($result = mysql_fetch_array ($query) $list =.$resulttitle. ; $content = str_replace (articletable, $list, $content); / / end of list generation Echo / / $content; $filename = test/test.html; $handle = fopen ($filename, w); / / create a file to open the file pointer. * Check if the file was created and writable * / If (. Is_writable ($filename) Die (file:.$filename.) is not writable. Please che

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论