Do the site to do has a certain scale, dynamic news release is essential. There are many ways to do this, and it is recommended to use a text file to generate it quickly and easily. Well, let's get down to work right away.
First, let's 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 you want to publish.
1, first, we limit the reading of the folder pointer.
$handle =dir ("C://news");
2, using a while statement, gets a pointer to each text file and outputs it one by one.
while ($file = $handle->read ())
{
Echo $file;
}
3, when the completion of the 2 operation, from the output of IIS observation, found on the page in addition to listing all the text file name, there will be more than two "strange symbols."
。
。。
The source of these two identities is not the scope of our discussion today, but their presence will affect the "press release" of our web page, so it is recommended to skip them with an if statement when they are displayed.
4, use Chop () to remove the ". txt" after the file name
$filename =chop ($file, ".");
In this way, $filename [0] is the headline of the news we asked for.
5, after the completion of the display will be linked. We assume that the document that handles the display of news is show.php;
Summing up above, we can write programs like this
$handle =dir ("C://news");
while ($file = $handle->read ())
{
if ($file! = '. ') && ($file! = ' ... '))
{
$filename =chop ($file, ".");
echo "Filename[0]";
}
?>
After that, the output of the text on the Web page is working, which is a lot of instructions. I will not repeat it.
The above introduces the implementation of dynamic PHP news and its skills, including the dynamic News of PHP content, I hope to be interested in PHP tutorial friends helpful.