Tips on PHP operation article list

Source: Internet
Author: User

Create a field in the database and record the file name. Each time a file is generated, the automatically generated file name is saved to the database. For recommended articles, you only need to point to the page in the specified folder where the static files are stored. Use PHP to operate the article list and save it as a string. 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 process the file in PHP:

PHP operation article list implementation code:

  1. <? Php
  2. $ Title = "http://siyizhu.com test template ";
  3. $ File = "TwoMax Inter test templet,
    <Br> 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. // Starts generating the list
  9. $ List = '';
  10. $ SQL = "select id, title, filename from article ";
  11. $ Query = mysql_query ($ SQL );
  12. While ($ result = mysql_fetch_array ($ query )){
  13. $ List. = '<a href ='. $ root. $ result ['filename'].'
    Target = _ blank>'. $ Result ['title'].'</A> <br>';
  14. }
  15. $ Content. = str_replace ("{articletable }"
    , $ List, $ content );
  16. // The generation list ends.
  17. // Echo $ content;
  18. $ Filename = "test/test.html ";
  19. $ Handle = fopen ($ filename, "w ");
    // Open the file pointer and create a file
  20. /*
  21. Check whether the file is created and writable.
  22. */
  23. If (! Is_writable ($ filename )){
  24. Die ("file:". $ filename. "cannot be written,
    Check its properties and try again! ");
  25. }
  26. If (! Fwrite ($ handle, $ content )){
    // Write information to a file
  27. Die ("generate File". $ filename. "failed! ");
  28. }
  29. Fclose ($ handle); // close the pointer
  30. Die ("creating File". $ filename. "successful! ");
  31. ?> 

The above code example shows how to use the PHP Operation Document list.


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.