Php code for automatically publishing news

Source: Internet
Author: User
Tags newsfile
The news file is stored in a fixed directory in the format of the ultimate file. txt, and the publishing of news can be completed automatically. This process consists of two parts: The first is the display of news, which is implemented by the shownews. php script. the code is as follows: <tableborder0width90 %> <〉〈? In the first line of a News File, php must display the news Title. The news file must be a text file (. tx News files are stored in a fixed directory in the format of a text file. txt, and the publishing of news can be completed automatically.

This process consists of two parts:

First, the display of news is implemented by the shownews. php script. the code is as follows:
<Table border = "0" width = "90%"> "〉
<〈? Php
// The title of the news in the first line of the News file
// The Newsfile contains the Upload file (.txt)
$ Newspath = "./news/"; // modify the news file directory
$ Newsfile = array ();
$ Hd = dir ($ newspath );
While ($ filename = $ hd-> read ()){
$ S = strtolower ($ filename );
If (strstr ($ s, ". txt ")){
$ Lastchanged = filemtime ($ newspath. $ filename );
$ Newsfile [$ filename] = $ lastchanged;
}
}
Arsort ($ newsfile );
For (reset ($ newsfile); $ key = key ($ newsfile); next ($ newsfile )){
Print "<tr> <td> n ";
$ Fa = file ($ newspath. $ key );
$ S = trim ($ fa [0]);
$ S = htmlspecialchars ($ s );
$ Lk = strlen ($ key );
$ A = substr ($ key, 0, $ LK-4 );
$ S = "<a href ="./pubnews. php? Id = ". $ a." "target = _ blank>". $ s. "</a> 〉";
Print $ s. "n ";
Print "(". date ("Y-m-d-H: I: s", $ newsfile [$ key]). ")
N ";
Print "</td> </tr> 〉";
}
$ Hd-> close ();
? > 〉
</Table> 〉

Put the code in the area where news is displayed:
<〈? Php
Require "./shownews. php ";
? > 〉

The second part is the publishing of news, which is implemented by the pupnews. php script. the code is as follows:
<〈? Php
If ($ id = "")
{
Header ("Location:./shownews. php ");
}
? > 〉
<Html> 〉
<Head> 〉
<Meta content = "chenqiang" name = Author> 〉
<〈? Php
$ Filename = "./news/". $ id. ". txt ";
$ Fa = file ($ filename );
$ N = count ($ fa );
$ S = trim ($ fa [0]);
$ S = htmlspecialchars ($ s );
$ T = "-news by waterwall ";
Print "<title>". $ s. $ t. "</title> n ";
? > 〉
</Head> 〉
<Body> 〉
<〈? Php
// Output text title
Print "<blockquote> n ";
Print "<B> <center>". $ s. "n ";
Print "</center> </B> 〉
<P> n ";
// Output text body
For ($ I = 1; $ I <$ n; $ I + = 1)
{
$ S = chop ($ fa [$ I]);
$ S = htmlspecialchars ($ s );
$ S = trim ($ s );
Print "". $ s ."
N ";
}
Print "</p> </blockquote> n ";
? > 〉
</Body> 〉
</Html> 〉

It can also be implemented using a database, which is just a file implementation method.

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.