Home > Article > Backend Development > Implementation of PHP dynamic news release and its techniques
To build a website of a certain scale, dynamic news releases are essential. There are many ways to implement it. It is recommended to use text files to generate it, which is fast, simple and trouble-free. Well, let's get to work right away.
First, we assume that there is already a folder named "news" under "c://news", which is used to store the text of the news. And we assume that the names of these texts are the titles of the news to be published.
1. First, we limit the reading of the folder pointer.
$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 the operation in step 2, observe the output of the results from IIS and find that in addition to listing the names of all text files, there will be two more "strange symbols" on the page.
.
. .
The origins of these two logos are beyond the scope of our discussion today, but their appearance will affect the "press release" of our web page, so it is recommended to use an if statement to skip them when displaying.
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 require.
5. After the display is completed, the link must be made. We assume that the file that handles displaying news is show.php;
To summarize the above, we can write the program like this
$handle=dir("c://news");
while($file=$handle->read())
{
if(($file!='.')&&($file!='..'))
{
$filename=chop($file,".");
echo " filename[0] ";
}
?>
The next step is to output text on the web page. There are already many instructions in this regard. I won't repeat it again.
The above introduces the implementation and techniques of PHP dynamic news publishing, including the content of PHP dynamic news. I hope it will be helpful to friends who are interested in PHP tutorials.