Use sockets: Get articles from newsgroups (iii) _php tutorial

Source: Internet
Author: User
Tags nntp nntp server
Read articles
Now that we've got the article number of the last article, it's easy to read the last 10 articles. RFC977 says that the article command can use either the article number or its message ID.
Note 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 not the same, 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;
}

echo "+----------------------+n";
echo "Article $bouclen";
echo "+----------------------+n";
echo "$articlen";
}

$boucle + +;
}

?>

We read the last 10 articles from this newsgroup on the server. You can also read the header information of an article by using the Head command, or use the body command to read the contents of the article.

Close connection
Finally, end the dialog with the NNTP server by calling the Fclose () function to close the socket.

Close connection
Fclose ($usenet _handle);
?>
For more information about fclose (), please refer to http://www.php.net/manual/function.fclose.php

Conclusion
In the above, 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 publish an article is not so complicated.
The next step is to write a web-based newsgroup client.
Storing these articles, using a search engine (such as http://www.htdig.org) to index the article is also very easy. In this way, you have a Web-based search newsgroup program.
An example of such a program can be obtained in http://www.phpindex.com/ng/.

http://www.bkjia.com/PHPjc/315316.html www.bkjia.com true http://www.bkjia.com/PHPjc/315316.html techarticle read the article since we've got the article number of the last article, it's easy to read the last 10 articles. RFC977 said that the article command can use both the article number ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.