PHP action article List related tips sharing _php tutorials

Source: Internet
Author: User

Create a field in the database, record the file name, each file is generated, the automatically generated file name is stored in the database, for the recommended article, just point to the page in the specified folder that holds the static file. Use PHP to manipulate the list of articles, save as a string, and replace this string when generating a page. For example, the table that places the list of articles in the page is added with the tag {articletable}, and in the PHP processing file:

PHP operation article List implementation code:

  1. < ? PHP
  2. $ title = "http://siyizhu.com test Template" ;
  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. Build list Start
  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. End of Build list
  17. Echo $content;
  18. $ filename = "Test/test.html" ;
  19. $ Handle = fopen ($filename, "w");
    Open file pointer, create file
  20. /*
  21. Check if the file is created and writable
  22. */
  23. if (!is_writable ($filename)) {
  24. Die ("File:". $filename. " Not writable,
    Please check its properties and try again! ");
  25. }
  26. if (!fwrite ($handle, $content)) {
    Writing information to a 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 how to use the PHP action article list.


http://www.bkjia.com/PHPjc/445955.html www.bkjia.com true http://www.bkjia.com/PHPjc/445955.html techarticle Create a field in the database, record the file name, each file is generated, the automatically generated file name into the database, for the recommended article, simply point to the file that holds the static file ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.