PHP generates static page code in the form of a list of articles

Source: Internet
Author: User
Keywords Web Programming PHP Tutorials
Tags code content create example file html list name

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

$title = "Tuo mai international test Template";
$file = "Twomax Inter test Templet,
Author:_max ">matrix@two_max";

$fp           = fopen ("temp.html", "R");
  $content   = fread ($fp, FileSize ("temp.html"));
  $content. = Str_replace ("{file}", $file, $content);
  $content. = Str_replace ("{title}", $title, $content);
 //  build list start
  $list = ';
  $sql = ' Select Id,title,filename from aspires ';
  $query = mysql_query ($sql);
  while ($result = Mysql_fetch_array ($query)) {
     $list. = '. $result [' title ']. '
  $content. = Str_replace ("{articletable}", $list, $content);
 //Generate list End
 //echo $content;
  $filename = "test/test.html";
  $handle     = fopen ($filename, "w"); Open the file pointer, create the file
to check whether the file was created and writable
  if (!is_writable ($filename)) {
      die ("File:". $filename. " Not writable, please check itsProperty and try again! ");
  if (!fwrite ($handle, $content)) { //write information to file
     die (build file. $filename. " Failed! ");
  fclose ($handle);//close pointer
  die (create file. $filename. " Success! ");

Related Article

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: 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.