Since we have obtained the number of the last article, it is easy to read the last 10 articles. In RFC977, the ARTICLE command can use either the ARTICLE number or its message ID. note that the article number is different from its message ID, because each news server SyntaxHighlighter. all ();
Read articles
Since we have obtained the number of the last article, it is easy to read the last 10 articles. In RFC977, the ARTICLE command can use either the ARTICLE number or its message ID.
Note that the article number is different from its message ID, because each news server assigns its own article number, therefore, the numbers of the same article on two different servers are different, and the message ID of the article is included in the header information of the article and is unique.
$ CfgLimit = 10;
// Upload last articles
$ Boucle = $ last-$ cfgLimit;
While ($ boucle <= $ last ){
Set_time_limit (0 );
Fputs ($ usenet_handle, "ARTICLE $ bouclen ");
$ Article = "";
$ Tmp = fgets ($ usenet_handle, 4069 );
If (substr ($ tmp, 0, 3 )! = & Quot; 220 & quot "){
Echo "+ ---------------------- + n ";
Echo "Error on article $ bouclen ";
Echo "+ ---------------------- + n ";
}
Else {
While ($ tmp! = ". Rn "){
$ Tmp = fgets ($ usenet_handle, 4096 );
$ Article. = $ tmp;
}
Echo "+ ---------------------- + n ";
Echo "Article $ bouclen ";
Echo "+ ---------------------- + n ";
Echo "$ articlen ";
}
$ Boucle ++;
}
?>
We read the last 10 articles from the newsgroup on the server ,. You can also use the HEAD command to read the header information of an article or the BODY command to read the content of the article.
Close connection
Finally, close the socket by calling the fclose () function to end the conversation with the NNTP server.
// Close connection
Fclose ($ usenet_handle );
?>
For more information about fclose (), see http://www.php.net/manual/function.fclose.php
Conclusion
In the above article, we see how to open, use, and then close a socket: connect to an NNTP server and retrieve some articles. Using the POST command to POST articles is not complicated.
The next step is to write a WEB-based newsgroup client.
It is also very easy to index these articles with a search engine, such as a http://www.htdig.org. In this way, you have a web-based newsgroup search program.
An example of such a program can be obtained at http://www.phpindex.com/ng.