Using sockets: Get articles from newsgroups (3)_PHP tutorial

WBOY
Release: 2016-07-21 16:06:50
Original
785 people have browsed it

Reading Articles
Now that we have the article number of the last article, it is easy to read the last ten articles. RFC977 says that the ARTICLE command can use either the article number or its message ID.
It should be noted here that the article number is different from its message ID because each news server assigns its own article number, so The number of the same article on two different servers is 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) != "220") {
echo "+------------- --------+n";
echo "Error on article $bouclen";
echo "+-------------------------- --+n";
}
else {
while($tmp!=".rn") {
$tmp = fgets($usenet_handle, 4096);
$article . =$tmp; bouclen";
echo "+----------------------+n";
echo "$articlen";
}

$boucle++;
}

?>

We read the last ten articles from this newsgroup on the server. You can also use the HEAD command to read the header information of the article, or the BODY command to read the article content.

Close the connection
Finally, close the socket by calling the fclose() function and end the conversation with the NNTP server.

                                                                                                                                             www.php.net/manual/function.fclose.php

Conclusion
In the above, we saw how to open, use and close a socket: connect to an NNTP server and retrieve some articles. Publishing an article using the POST command is not much more complicated.
The next step is to write a WEB-based newsgroup client.
It is also very easy to store these articles and index them using a search engine (such as http://www.htdig.org). In this way, you have a web-based program for searching newsgroups.
An example of such a program can be obtained at http://www.phpindex.com/ng/.​



http://www.bkjia.com/PHPjc/315316.html

www.bkjia.com

true

http: //www.bkjia.com/PHPjc/315316.html

Read article Now that we have got the article number of the last article, reading the last ten articles is Very easy. RFC977 says that the ARTICLE command can use article numbers...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!