News files are stored in a fixed directory in the format of a text file,. txt, and the press release can be done automatically.
The process consists of two parts:
The first is the display of the news, implemented by the shownews.php script, with the following code:
〈table border= "0" width= "90%"
〈?php
The title of the news in the first line of the news file
The news file must be a text file (. txt)
$newspath = "./news/"; Modify the directory where the news files are stored
$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 year M D Day-H:i:s", $newsfile [$key]). ")
n ";
print "〈/td〉〈/tr〉";
}
$HD-〉close ();
?〉
〈/table〉
Put the code where the news is displayed:
〈?php
Require "./shownews.php";
?〉
The second part is the release of the news, 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 Caption
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〉
Database can also be implemented, this is just the way the file form.
http://www.bkjia.com/PHPjc/631798.html www.bkjia.com true http://www.bkjia.com/PHPjc/631798.html techarticle news files are stored in a fixed directory in the format of a text file,. txt, and the press release can be done automatically. The process consists of two parts: the first is the display of news, by shownews ....