PHP operation article list related skills sharing_PHP tutorial

WBOY
Release: 2016-07-15 13:34:43
Original
1156 people have browsed it

Create a field in the database and record the file name. Every time a file is generated, the automatically generated file name is stored in the database. For recommended articles, just point to Just store the page in the specified folder where the static files are stored. Use PHP to operate the article list, save it as a string, and replace this string when generating the page. For example, add the mark {articletable} to the table where the article list is placed on the page, and in the PHP processing file:

PHP operation article list implementation code:

  1. < ?php  
  2. $title = "http://siyizhu.com测试模板";  
  3. $file = "TwoMax Inter test templet,

    author:Matrix@Two_Max"
    ;  
  4. $fp = fopen ("temp.html","r");  
  5. $content = fread ($fp,filesize ("temp.html"));  
  6. $content = str_replace ("{file}",$file,$content);  
  7. $content = str_replace ("{title}",$title,$content);   
  8. // 生成列表开始  
  9. $list = '';  
  10. $sql = "select id,title,filename from article";  
  11. $query = mysql_query ($sql);  
  12. while ($result = mysql_fetch_array ($query)){  
  13. $list .'.$root.$result['filename'].' 
    target=_blank>'.$result['title'].'a><br>';  
  14. }  
  15. $content .str_replace ("{articletable}"
    ,$list,$content);   
  16. //生成列表结束  
  17. // echo $content;   
  18. $filename = "test/test.html";  
  19. $handle = fopen ($filename,"w");
     //打开文件指针,创建文件  
  20. /*  
  21. 检查文件是否被创建且可写  
  22. */  
  23. if (!is_writable ($filename)){  
  24. die ("文件:".$filename."不可写,
    Please check its properties and try again! ");
  25. }
  26. if (!fwrite ($handle,$content)){
    //Write information File
  27. die ("Generate file".$filename."Failed!");
  28. }
  29. fclose ($handle); //Close pointer
  30. die ("Create file".$filename."Success!");
  31. ?>

The above code example is related to the use of PHP operation article list Method.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445955.htmlTechArticleCreate a field in the database and record the file name. Each time a file is generated, the automatically generated file name is stored in the database. , for recommended articles, just point to the specified file where the static files are stored...
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template