The realization of dynamic news release and its skill _php Foundation

Source: Internet
Author: User
Tags chop
Do the site to do have a certain scale, dynamic news release is essential. There are many ways to implement it, and it is recommended that you use a text file to generate it quickly and easily. Well, let's get to work at once.
First, we assume that there is already a folder named "News", under "C://news", to store the text of the news. And we assume that the name of the text is the title of the news to be published.
1, first, we limit the reading of the folder pointer.
$handle =dir ("C://news");
2, with a while statement, gets the pointer to each text file and outputs it one by one.
while ($file = $handle->read ())
{
Echo $file;
}
3, after 2 of the operation, from the output of the results of the IIS observation, found on the page in addition to enumerating the names of all text files, there will be more than two "strange symbols."

。。
The origins of these two identities are not the scope of our discussion today, but their presence will affect the "press release" of our web page, so it is advisable to skip them with an if statement when they are displayed.
4, using Chop () to remove "txt" after the filename
$filename =chop ($file, ".");
In this way, $filename [0] is the headline of the news we are asking for.
5, the completion of the display will be done after the link. We assume that the document that handles the display of news is show.php;
Summing up the above, we can write a program like this
?
$handle =dir ("C://news");
while ($file = $handle->read ())
{
if ($file!= '. ') && ($file!= ' ... '))
{
$filename =chop ($file, ".");
echo "<a href= ' show.php '? id= $filename [0]> filename[0] </a>";
}
?>
After that is the output of the text on the Web page work, this aspect of the description has been many. I will not repeat it.

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.