WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Functions to access a NNTP/NNRP newsserver. Complete set with examples is at ftp://ftp.nederland.net/pub/nnrplib
Categories : Search, PHP, Complete Programs Update Picture
Sander Steffann
Date : Jan 17th 1999
Grade : 3 of 5 (graded 2 times)
Viewed : 6091
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Sander Steffann
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

<?php
/*
NNRPlib - A NNRP library
Copyright (C) 1998 SJM Steffann & Computel Standby BV

This library is free software; you can redistribute it
and/or
modify it under the terms of the GNU Library General
Public
License as published by the Free Software Foundation;
either
version 2 of the License, or (at your option) any
later version.

This library is distributed in the hope that it will
be useful,
but WITHOUT ANY WARRANTY; without even the implied
warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU
Library General Public License for more details.

You should have received a copy of the GNU Library
General Public
License along with this library; if not, write to the
Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
02139, USA.

Complete set with examples at
ftp://ftp.nederland.net/pub/nnrplib/
*/

function nnrp_open($server) {
global $NNRP_GLOBAL_STATUS;

$nnrp = fsockopen($server, 119);
if ($nnrp < 0) return -1;

$line = fgets($nnrp, 1024);
$NNRP_GLOBAL_STATUS[$nnrp][ "LASTRESULT"] = substr($line,
0, 3);
$NNRP_GLOBAL_STATUS[$nnrp][ "LASTRESULTTEXT"] = substr
($line, 4, 1024);
if (substr($line, 0, 2) <> "20") return -1;

fputs($nnrp, "MODE READER\r\n");

$line = fgets($nnrp, 1024);
$NNRP_GLOBAL_STATUS[$nnrp][ "LASTRESULT"] = substr($line,
0, 3);
$NNRP_GLOBAL_STATUS[$nnrp][ "LASTRESULTTEXT"] = substr
($line, 4, 1024);
if (substr($line, 0, 2) <> "20") return -1;

if (substr($line, 2, 1) == "0") {
$NNRP_GLOBAL_STATUS[$nnrp][ "POST"] = 1;
} else {
$NNRP_GLOBAL_STATUS[$nnrp][ "POST"] = 0;
}

$NNRP_GLOBAL_STATUS[ "group"] = "";
$NNRP_GLOBAL_STATUS[ "count"] = 0;
$NNRP_GLOBAL_STATUS[ "first"] = 0;
$NNRP_GLOBAL_STATUS[ "last"] = 0;

return $nnrp;
}

function nnrp_authinfo($nnrp, $user, $pass) {
global $NNRP_GLOBAL_STATUS;

fputs($nnrp, "AUTHINFO USER $user\r\n");
$line = fgets($nnrp, 1024);
$NNRP_GLOBAL_STATUS[$nnrp][ "LASTRESULT"] = substr($line,
0, 3);
$NNRP_GLOBAL_STATUS[$nnrp][ "LASTRESULTTEXT"] = substr
($line, 4, 1024);
if (substr($line, 0, 3) <> "381") return -1;

fputs($nnrp, "AUTHINFO PASS $pass\r\n");
$line = fgets($nnrp, 1024);
$NNRP_GLOBAL_STATUS[$nnrp][ "LASTRESULT"] = substr($line,
0, 3);
$NNRP_GLOBAL_STATUS[$nnrp][ "LASTRESULTTEXT"] = substr
($line, 4, 1024);
if (substr($line, 0, 3) <> "281") return -1;

return 0;
}

function nnrp_list($nnrp) {
global $NNRP_GLOBAL_STATUS;

fputs($nnrp, "LIST\r\n");
$line = fgets($nnrp, 1024);
$NNRP_GLOBAL_STATUS[$nnrp][ "LASTRESULT"] = substr($line,
0, 3);
$NNRP_GLOBAL_STATUS[$nnrp][ "LASTRESULTTEXT"] = substr
($line, 4, 1024);
if (substr($line, 0, 3) <> "215") return -1;

$i = 0;
while (substr($line = fgets($nnrp, 1024), 0, 1) <>
".") {
while ((strlen($line) > 0) && (($line[strlen
($line)-1] == "\n") || ($line[strlen($line)-1] == "\r"))) $line =
substr($line, 0, strlen($line)-1);
$tok = strtok($line, " ");
$groups[$i] = $tok;
$tok = strtok($line, " ");
$groups[$i][ "last"] = $tok;
$tok = strtok($line, " ");
$groups[$i][ "first"] = $tok;
$tok = strtok($line, " ");
$groups[$i][ "post"] = (($tok == "y") ? true :
false);
$i++;
}
$groups[ "count"] = $i;
return $groups;
}

function nnrp_newgroups($nnrp, $timestamp, $distr= "") {
global $NNRP_GLOBAL_STATUS;

if (strlen($distr) > 0) {
$distr = "<".$distr. ">";
}

$datestring = gmdate( "ymd His", $timestamp);

fputs($nnrp, "NEWGROUPS $datestring GMT $distr\r\n");
$line = fgets($nnrp, 1024);
$NNRP_GLOBAL_STATUS[$nnrp][ "LASTRESULT"] = substr($line,
0, 3);
$NNRP_GLOBAL_STATUS[$nnrp][ "LASTRESULTTEXT"] = substr
($line, 4, 1024);
if (substr($line, 0, 3) <> "231") return -1;

$i = 0;
while (substr($line = fgets($nnrp, 1024), 0, 1) <>
".") {
while ((strlen($line) > 0) && (($line[strlen
($line)-1] == "\n") || ($line[strlen($line)-1] == "\r"))) $line =
substr($line, 0, strlen($line)-1);
$tok = strtok($line, " ");
$groups[$i] = $tok;
$tok = strtok($line, " ");
$groups[$i][ "last"] = $tok;
$tok = strtok($line, " ");
$groups[$i][ "first"] = $tok;
$tok = strtok($line, " ");
$groups[$i][ "post"] = (($tok == "y") ? true :
false);
$i++;
}
$groups[ "count"] = $i;
return $groups;
}

function nnrp_newnews($nnrp, $newsgroups, $timestamp, $distr= "")
{
global $NNRP_GLOBAL_STATUS;

if (strlen($distr) > 0) {
$distr = "<".$distr. ">";
}

$datestring = gmdate( "ymd His", $timestamp);

fputs($nnrp, "NEWNEWS $newsgroups $datestring GMT
$distr\r\n");
$line = fgets($nnrp, 1024);
$NNRP_GLOBAL_STATUS[$nnrp][ "LASTRESULT"] = substr($line,
0, 3);
$NNRP_GLOBAL_STATUS[$nnrp][ "LASTRESULTTEXT"] = substr
($line, 4, 1024);
if (substr($line, 0, 3) <> "230") return -1;

$i = 0;
while (substr($line = fgets($nnrp, 1024), 0, 1) <>
".") {
while ((strlen($line) > 0) && (($line[strlen
($line)-1] == "\n") || ($line[strlen($line)-1] == "\r"))) $line =
substr($line, 0, strlen($line)-1);
$messages[$i] = $line;
$i++;
}
$messages[ "count"] = $i;
return $messages;
}

function nnrp_post($nnrp, $newsgroups, $from, $subject, $message,
$reply_to= "", $organization= "", $follow_up= "", $references= "") {
global $NNRP_GLOBAL_STATUS;
global $SERVER_NAME;

fputs($nnrp, "POST\r\n");
$line = fgets($nnrp, 1024);
$NNRP_GLOBAL_STATUS[$nnrp][ "LASTRESULT"] = substr($line,
0, 3);
$NNRP_GLOBAL_STATUS[$nnrp][ "LASTRESULTTEXT"] = substr
($line, 4, 1024);
if (substr($line, 0, 3) <> "340") return -1;

fputs($nnrp, "From: $from\r\n");
if (strlen($reply_to) > 0) {
fputs($nnrp, "Reply-To: $reply_to\r\n");
}
fputs($nnrp, "Sender: gateway@$SERVER_NAME\r\n");
fputs($nnrp, "Newsgroups: $newsgroups\r\n");
fputs($nnrp, "Subject: $subject\r\n");
if (strlen($organization) == 0) {
$organization = "NNRP Gateway at http://
$SERVER_NAME/\r\n";
}
fputs($nnrp, "Organization: $organization\r\n");
if (strlen($follow_up) > 0) {
fputs($nnrp, "Followup-To: $follow_up\r\n");
}
if (strlen($references) > 0) {
fputs($nnrp, "References: $references\r\n");
}
fputs($nnrp, "\r\n");

$newmessage = ereg_replace( "([^\r\n])$", "\\1\r\n",
$message);
$newmessage = ereg_replace( "\n\r", "\r\n",$newmessage);
$newmessage = ereg_replace( "([^\r])\n", "\\1\r\n",
$newmessage);
$newmessage = ereg_replace( "\r([^\n])", "\r\n\\1",
$newmessage);
$newmessage = ereg_replace( "\r$", "\r\n", $newmessage);
$newmessage = ereg_replace( "^\n", "\r\n", $newmessage);

$newmessage = ereg_replace( "\r\n\.([^\.])", "\r\n..\\1",
$newmessage);
$newmessage = ereg_replace( "\r\n\.$", "\r\n..",
$newmessage);

fputs($nnrp, "$newmessage");
fputs($nnrp, ".\r\n");

$line = fgets($nnrp, 1024);
$NNRP_GLOBAL_STATUS[$nnrp][ "LASTRESULT"] = substr($line,
0, 3);
$NNRP_GLOBAL_STATUS[$nnrp][ "LASTRESULTTEXT"] = substr
($line, 4, 1024);
if (substr($line, 0, 3) <> "240") return -1;

return 0;
}

function nnrp_listgroup($nnrp, $group) {
global $NNRP_GLOBAL_STATUS;

fputs($nnrp, "LISTGROUP $group\r\n");
$line = fgets($nnrp, 1024);
$NNRP_GLOBAL_STATUS[$nnrp][ "LASTRESULT"] = substr($line,
0, 3);
$NNRP_GLOBAL_STATUS[$nnrp][ "LASTRESULTTEXT"] = substr
($line, 4, 1024);
if (substr($line, 0, 3) <> "211") return -1;

$i = 0;
while (substr($line = fgets($nnrp, 1024), 0, 1) <>
".") {
while ((strlen($line) > 0) && (($line[strlen
($line)-1] == "\n") || ($line[strlen($line)-1] == "\r"))) $line =
substr($line, 0, strlen($line)-1);
$tok = strtok($line, " ");
$articles[$i] = intval($tok);
$i++;
}
$articles[ "count"] = $i;
return $articles;
}

function nnrp_group($nnrp, $group) {
global $NNRP_GLOBAL_STATUS;

fputs($nnrp, "GROUP $group\r\n");
$line = fgets($nnrp, 1024);
$NNRP_GLOBAL_STATUS[$nnrp][ "LASTRESULT"] = substr($line,
0, 3);
$NNRP_GLOBAL_STATUS[$nnrp][ "LASTRESULTTEXT"] = substr
($line, 4, 1024);
if (substr($line, 0, 3) <> "211") return -1;

while ((strlen($line) > 0) && (($line[strlen($line)-1]
== "\n") || ($line[strlen($line)-1] == "\r"))) $line = substr($line,
0, strlen($line)-1);

$tok = strtok($line, " "); /* $tok = 211
*/
$tok = strtok( " "); /*
$tok = nr */
$NNRP_GLOBAL_STATUS[ "count"] = $info[ "count"] = intval
($tok);
$tok = strtok( " "); /*
$tok = low */
$NNRP_GLOBAL_STATUS[ "first"] = $info[ "first"] = intval
($tok);
$tok = strtok( " "); /*
$tok = high */
$NNRP_GLOBAL_STATUS[ "last"] = $info[ "last"] = intval
($tok);

$NNRP_GLOBAL_STATUS[ "group"] = $group;

return $info;
}

function nnrp_article($nnrp, $article) {
global $NNRP_GLOBAL_STATUS;

fputs($nnrp, "ARTICLE $article\r\n");
$line = fgets($nnrp, 1024);
$NNRP_GLOBAL_STATUS[$nnrp][ "LASTRESULT"] = substr($line,
0, 3);
$NNRP_GLOBAL_STATUS[$nnrp][ "LASTRESULTTEXT"] = substr
($line, 4, 1024);
if (substr($line, 0, 3) <> "220") return -1;

$i = 0;
while (substr($line = fgets($nnrp, 1024), 0, 1) <>
".") {
while ((strlen($line) > 0) && (($line[strlen
($line)-1] == "\n") || ($line[strlen($line)-1] == "\r"))) $line =
substr($line, 0, strlen($line)-1);
$data[$i] = $line;
$i++;
}
$data[ "count"] = $i;

return $data;
}

function nnrp_overviewformat($nnrp, $full=false) {
global $NNRP_GLOBAL_STATUS;

fputs($nnrp, "LIST overview.fmt\r\n");
$line = fgets($nnrp, 1024);
$NNRP_GLOBAL_STATUS[$nnrp][ "LASTRESULT"] = substr($line,
0, 3);
$NNRP_GLOBAL_STATUS[$nnrp][ "LASTRESULTTEXT"] = substr
($line, 4, 1024);
if (substr($line, 0, 3) <> "215") return -1;

$i = 0;
while (substr($line = fgets($nnrp, 1024), 0, 1) <>
".") {
while ((strlen($line) > 0) && (($line[strlen
($line)-1] == "\n") || ($line[strlen($line)-1] == "\r"))) $line =
substr($line, 0, strlen($line)-1);
if ($full == false) {
$headers[$i] = strtok($line, ":");
} else {
$headers[$i][ "name"] = strtok($line, ":");
$headers[$i][ "full"] = (strtolower(strtok(
"\n")) == "full");
}
$i++;
}
$headers[ "count"] = $i;

return $headers;
}

function nnrp_overview($nnrp, $first= "none", $last= "none") {
global $NNRP_GLOBAL_STATUS;

if ($first == "none") {
$first = $NNRP_GLOBAL_STATUS[ "first"];
$last = $NNRP_GLOBAL_STATUS[ "last"];
} else {
if ($last == "none") {
$last = $first;
}
}

if (($headers = nnrp_overviewformat($nnrp, true)) == -1)
{
return -1;
}

fputs($nnrp, "XOVER ".$first. "-".$last. "\r\n");
$line = fgets($nnrp, 1024);
$NNRP_GLOBAL_STATUS[$nnrp][ "LASTRESULT"] = substr($line,
0, 3);
$NNRP_GLOBAL_STATUS[$nnrp][ "LASTRESULTTEXT"] = substr
($line, 4, 1024);
if (substr($line, 0, 3) <> "224") return -1;

$i = 0;
while (substr($line = fgets($nnrp, 1024), 0, 1) <>
".") {
while ((strlen($line) > 0) && (($line[strlen
($line)-1] == "\n") || ($line[strlen($line)-1] == "\r"))) $line =
substr($line, 0, strlen($line)-1);
$art = intval(strtok($line, "\t"));
$j = 0;
while ($j < $headers[ "count"]) {
if ($headers[$j][ "full"]) {
$overview[$art][$headers[$j][ "name"]]
= substr(strtok( "\t"), strlen($headers[$j][ "name"])+2, 1024);
} else {
$overview[$art][$headers[$j][ "name"]]
= strtok( "\t");
}
$j++;
}
$i++;
}
$overview[ "count"] = $i;

return $overview;
}

function nnrp_head($nnrp, $article) {
global $NNRP_GLOBAL_STATUS;

fputs($nnrp, "HEAD $article\r\n");
$line = fgets($nnrp, 1024);
$NNRP_GLOBAL_STATUS[$nnrp][ "LASTRESULT"] = substr($line,
0, 3);
$NNRP_GLOBAL_STATUS[$nnrp][ "LASTRESULTTEXT"] = substr
($line, 4, 1024);
if (substr($line, 0, 3) <> "221") return -1;

$i = 0;
while (substr($line = fgets($nnrp, 1024), 0, 1) <>
".") {
while ((strlen($line) > 0) && (($line[strlen
($line)-1] == "\n") || ($line[strlen($line)-1] == "\r"))) $line =
substr($line, 0, strlen($line)-1);
$data[$i] = $line;
$i++;
}
$data[ "count"] = $i;

return $data;
}

function nnrp_body($nnrp, $article) {
global $NNRP_GLOBAL_STATUS;

fputs($nnrp, "BODY $article\r\n");
$line = fgets($nnrp, 1024);
$NNRP_GLOBAL_STATUS[$nnrp][ "LASTRESULT"] = substr($line,
0, 3);
$NNRP_GLOBAL_STATUS[$nnrp][ "LASTRESULTTEXT"] = substr
($line, 4, 1024);
if (substr($line, 0, 3) <> "222") return -1;

$i = 0;
while (substr($line = fgets($nnrp, 1024), 0, 1) <>
".") {
while ((strlen($line) > 0) && (($line[strlen
($line)-1] == "\n") || ($line[strlen($line)-1] == "\r"))) $line =
substr($line, 0, strlen($line)-1);
$data[$i] = $line;
$i++;
}
$data[ "count"] = $i;

return $data;
}

function nnrp_close($nnrp) {
global $NNRP_GLOBAL_STATUS;

fputs($nnrp, "QUIT\r\n");
$line = fgets($nnrp, 1024);
$NNRP_GLOBAL_STATUS[$nnrp][ "LASTRESULT"] = substr($line,
0, 3);
$NNRP_GLOBAL_STATUS[$nnrp][ "LASTRESULTTEXT"] = substr
($line, 4, 1024);
if (substr($line, 0, 3) <> "205") return -1;

$NNRP_GLOBAL_STATUS[ "group"] = "";
$NNRP_GLOBAL_STATUS[ "count"] = 0;
$NNRP_GLOBAL_STATUS[ "first"] = 0;
$NNRP_GLOBAL_STATUS[ "last"] = 0;

fclose($nnrp);
return 0;
}

function nnrp_lastresult($nnrp) {
global $NNRP_GLOBAL_STATUS;

return $NNRP_GLOBAL_STATUS[$nnrp][ "LASTRESULT"];
}

function nnrp_lastresulttext($nnrp) {
global $NNRP_GLOBAL_STATUS;

return $NNRP_GLOBAL_STATUS[$nnrp][ "LASTRESULTTEXT"];
}
?>



Searches through a local INN server's discussions
Categories : Search, Complete Programs, PHP
free, search engine, indexing, system, information, web, ftp, http, free, software, cgi, php, MySQL, database, php3, FreeBSD, Linux, Unix, UdmSearch
Categories : MySQL, Complete Programs, PHP, Databases, Search
Client classes for Dictionary servers UPDATED: 2000-06-06
Categories : Network, Search, Complete Programs, PHP Classes, PHP
DirtSearch Version 3.5 full function robust PHP and MySQL (and other databases) Site or Web Wide Search Engine
Categories : PHP, MySQL, Complete Programs, Search, Databases
phpYellow Pages Standard
Categories : PHP, Complete Programs, Databases, Directories, Search
Accepts a database & hostname from a user and then HTTP username and password. Uses this to connect to a MySQL database. Produces a form based on the tables it finds there to allow the user to do SELECTs, INSERTs, and DELETEs.
Categories : Databases, PHP, MySQL, Complete Programs
PHP-MySQL shopping cart
Categories : PHP, Ecommerce, Complete Programs
Point and Click Interface ala MS Access for creating SQL statements.
Categories : MySQL, Complete Programs, General SQL, PHP, Databases
phpCards - PHP/mySQL postcard script with web based admin to add, edit, and delete cards and categories. Very easy to install.
Categories : PHP, Complete Programs, HTML and PHP, MySQL
Expose - PHP template engine, supports server and client-sided caching,a plugin system, multiple languages, template script language is based on PHP itself.
Categories : PHP, PHP Classes, Templates, Complete Programs
Tropicalm Genetree Family (MySQL based family tree)
Categories : PHP, Interfaces, Databases, MySQL, Complete Programs
phpWebCam v1.0- Webcam management software - Automatically checks if you're online, and comes with a caption tool capable of handling multiple users.
Categories : PHP, Complete Programs, HTML and PHP
a class for doing payments to a cybercash server
Categories : Ecommerce, Complete Programs, PHP Classes, PHP
Web Self Service Resource Scheduler Using php3 and MySQL
Categories : PHP, Complete Programs, MySQL
A set of functions sitting on top of the abstraction layer that makes it a little easier to do SQL stuff. Documentation is within
Categories : Databases, ODBC, Complete Programs, PHP
 Wayne Spivak wrote :53
Looks like a great product - just have one small 
problem, first letter of all my newsgroups is truncated, 
thus a newsgroup called ps-general is now s-general, 
and can`t be accessed.