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 the program in this way.
<?
$ 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.