A website must be developed on a certain scale. Dynamic news publishing is essential. There are many implementation methods. We recommend that you use text files to generate them quickly and easily. Okay. Let's get started immediately.
First, assume that there is already a folder named "news", which is used to store News Text under "C: // News. In addition, we assume that the names of these texts are the titles of the news to be published.
1. First, read the pointer of the folder only.
$ Handle = Dir ("C: // News ");
2. Use a while statement to obtain the pointers of each text file and output them one by one.
While ($ file = $ handle-> Read ())
{
Echo $ file;
}
3. After completing step 2, the IIS observes the result output and finds that there will be two "strange symbols" in addition to listing the names of all text files on the page ".
.
..
The source of these two identifiers is not the scope of our discussion today, however, their appearance will affect the "News Publishing" of our webpage. Therefore, we recommend that you use an if statement to drop their skip when displaying the content.
4. Use chop () to remove ". txt" after the file name"
$ Filename = chop ($ file ,".");
In this way, $ filename [0] is the title of the news we requested.
5. After the display is complete, a link is required. Let's assume that the file for processing the news is show. php;
To sum up the above, we can write it like this Program
<?
$ 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, I will output text on the web page. There are many instructions in this regard. I will not repeat it.
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.