PHP Automatic Update news DIY

Source: Internet
Author: User
Keywords PHP auto Update DIY
Tags filetime save file
When we browse some websites, we often see that some news is just updated soon, if it is manual maintenance, it will be a very tedious job. However, we can use the program to control the implementation of the update operation, things will become very convenient (I am not lazy).
 
Here, I use PHP to implement this function. The principle is that according to the time of the press release in reverse order, and then on a page display the news connection list, each connection corresponds to a news content page. Here's how:

First, in your site under the establishment of a directory, the edited news pages are saved in this directory, all the news pages in the future are put here, easy to maintain. The News page format is hypertext (don't say you don't have HTML), the first behavior "<HTML> <HEAD> <TITLE> News headlines </TITLE> </HEAD>" (reason is explained later).

Second, write the program, realize the News Automatic Update function (assuming the file name is paixu.php)

The source program is as follows:

<?php$fp=array ("filename" => "", "Filetime" => "", "Firstline" => "");//Create an array, save the file name, the first line of files $dd=dir (' News Save Directory ');//Read the Save directory of the news file $i =0;clearstatcache (), while ($file = $dd->read ())//loops through the files in the directory {if (Is_file ($dd->path. "). /". $file)" {$fp [$i] ["filename"]= $dd->path. " /". $file;//Save file name $fr=fopen ($dd->path." /". $file," R "), $FP [$i] [" Firstline "]=FGETSS ($FR, 60);//Remove HTML tags and save the first line of the file (that is why we want to write the first line of the news page in the required format) fclose ($FR); if ($ Time=date ("Y m D h:i", Filemtime ($dd->path.) /". $file)")//Save the file time as a sort condition {$fp [$i] ["FILETIME"]= $time;} $i + +;}} $i =count ($FP);//$i-=4;for ($j =0; $j $i; $j + +)//According to the bubbling algorithm (the computer newspaper has an article introduced, I don't wordy) for ($k = $i; $k > $j; $k-) if ($fp [$j] FILETIME "]<= $fp [$k] [" FILETIME "]) {$c = $fp [$j] [" filetime "]; $fname = $fp [$j] [" filename "]; $fcontent = $fp [" $j "] [" Firstline "], $fp [$j] [filetime]]= $fp [$k] [filetime], $fp [$j] [" filename "]= $fp [$k] [" filename "]; $fp [$j] [Firstline "]= $fp [$k] [firstline] $fp [$k] [" FILETIME "]= $c//line30$fp[$k] [" filename "]= $fname; $fp [$k] [Firstline]]=$ Fcontent;} for ($i =0; $i <= (Count ($fp)-4), $i + +)//Read the saved file information, make the appropriate connection {echo "<tr> <td>"; echo "<a HRef= ". $fp [$i] [filename]." > ". $fp [$i] [firstline]." </a> "; echo" </td> <td class=font1> "; echo" (". $fp [$i] [" FILETIME "].") <br> \ n "; echo" </td> </tr> ";} $dd->close ();? >



Third, put the program and directory on your website, and then in the browser typing http://directory/panxu.php, can you see?

Finally, a few more words (I do not want to make more money, mainly to serve the serving), your site must support PHP features.

And, I just provide the basic functions, you can add more control functions, as well as the page decoration and landscaping work, it is up to you (what?). Say I'm not responsible for the end? I am bitter ...). All right, let's go. There is something wrong, but also please more advice, you can send email:zbclh@sina.com contact me to communicate.


The above is the PHP Automatic Update news DIY content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!


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