Heim  >  Artikel  >  Backend-Entwicklung  >  PHP操作文章列表相关技巧分享_PHP教程

PHP操作文章列表相关技巧分享_PHP教程

WBOY
WBOYOriginal
2016-07-15 13:34:431121Durchsuche

在数据库中创建字段,记录文件名,每生成一个文件,将自动生成的文件名存入数据库,对于推荐文章,只需指向存放静态文件的指定文件夹中的该页面即可。 利用PHP操作文章列表,存为字符串,生成页面时替换此字符串即可。如,在页面中放置文章列表的表格加入标记{articletable},而在 PHP处理文件中:

PHP操作文章列表实现代码:

  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."不可写,
    请检查其属性后重试!");  
  25. }  
  26. if (!fwrite ($handle,$content)){ 
    //将信息写入文件  
  27. die ("生成文件".$filename."失败!");  
  28. }   
  29. fclose ($handle); //关闭指针   
  30. die ("创建文件".$filename."成功!");  
  31. ?> 

以上这段代码示例就是PHP操作文章列表的相关使用方法。


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/445955.htmlTechArticle在数据库中创建字段,记录文件名,每生成一个文件,将自动生成的文件名存入数据库,对于推荐文章,只需指向存放静态文件的指定文件...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn