PHP Code _php Tutorials for automatically publishing news

Source: Internet
Author: User
Tags newsfile
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 ....

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