Source of: php3/rdfparser.php3

<?
//
// RDFPARSER 0.2 - Mike Krus  mwkrus@yahoo.com   http://mkrus.free.fr/
//
// You may use this code for whatever purpose as long you keep this message
// and don't blame me if does not work!!
//


if(isset($protectmultiincrdfnws)) return;
$protectmultiincrdfnws 1;

error_reporting(E_ALL);


include 
"newsformat.inc";


function 
getNextToken($ofile)
{
    static 
$char "";

    
$token "";

    
$intoken 0;
    
$intag 0;
    while (
1) {
        if(
$char == "") {
            
$char fgetc($ofile);
            if(
feof($ofile)) break;
        }
        if(
$char == "\n") {
            
$char "";
            continue;
        }
        if((
$char == " " || $char == "\t") && !($intag || $intoken)) {
            
$char "";
            continue;
        }
        if(
$intoken == 0) {
            if(
$char == "<"$intag 1;
                        else 
$intag 0;
            
$intoken 1;
            
$token .= $char;
        } else {
            if(
$intag == 1) {
                
$token .= $char;
                if(
$char == ">") {
                    
$char "";
                    break;
                }
            } else {
                if(
$char == "<") break;
                
$token .= $char;
            }
        }
        
$char "";
    }
    return 
ltrim(Chop($token));
}


function 
parserdf($hostname$uri$port 80$maxitems 0)
{
    
$itemcount 0;
    
$cfile 0;

    
$inchannel 0;
    
$initem 0;
    
$intitle 0;
    
$intxtinput 0;
    
$inlink 0;
    
$inname 0;

    
$chtitle "";
    
$churl "";
    
$ittitle "";
    
$iturl "";
    
$tiname "";
    
$tiurl "";
    
$tititle "";


    
$header_passed 0;
    
$cache "cache/cache." $hostname ".txt";
    
$comment "(cached)";

    if(
file_exists($cache)) {
        
$ctime fileMtime($cache);
        if(
fileSize($cache) < 20$ctime = -1;
    } else 
$ctime = -1;
    
$ntime Time();
    
$dtime $ntime $ctime;

    
$uncache 0;
    
$linelengh 1024;
    
$filedate "";

    
$uri urldecode($uri);

    global 
$nocache;
    if(isset(
$nocache) || $dtime $ntime || $dtime 1800) {
        
$cfile fopen($cache"w");

        
$fpread fsockopen("$hostname"$port, &$errno, &$errstr);
        if(!
$fpread) {
                echo 
"Error connecting to $hostname: $errstr<br>\n";
                return;
        } else {
            
fputs($fpread"GET $uri HTTP/1.0\n");
            
fputs($fpread"User-Agent: PHP RDFParser/0.2  mkrus@free.fr\n");
            
fputs($fpread"Host: " $hostname ":80\n");
            
fputs($fpread"Accept: */*\n\n");

            
$str fgets($fpread$linelengh);
            
$id strstr($str"404");
            if(
$id != "") {
                echo 
"Document <A HREF=\"http://$hostname$uri\">http://$hostname$uri</A> not found\n";
                return;
            }

            while (!
feof($fpread)) {
                if (
$header_passed == 1) {
                    
$str getNextToken($fpread);

                    if(
$str == "<channel>") {
                        
$inchannel 1;
                    } elseif(
$str == "</channel>") {
                        if(
$inchannel) {
                            
writeHeader($cfile$chtitle$churl,
                                        
"http://" $hostname ":" $port $uri);
                        }
                        
$inchannel 0;
                        
$initem 0;
                    } elseif(
$str == "<title>") {
                        
$intitle 1;
                    } elseif(
$str == "</title>") {
                        
$intitle 0;
                    } elseif(
$str == "<item>") {
                        
$ittitle "";
                        
$iturl "";
                        if(
$inchannel) {
                            
$inchannel 0;
                            
writeHeader($cfile$chtitle$churl,
                                        
"http://" $hostname ":" $port $uri);
                        }
                        if(
$initem) {
                            
writeItem($cfile$ittitle$iturl);
                            
$itemcount++;
                        }
                        
$initem 1;
                    } elseif(
$str == "</item>" && $initem) {
                        
$initem 0;
                        
writeItem($cfile$ittitle$iturl);
                        
$itemcount++;
                    } elseif(
$str == "</a>" && $initem) {
                        
$initem 0;
                        
$ittitle .= $str;
                        
writeItem($cfile$ittitle$iturl);
                        
$itemcount++;
                    } elseif(
$str == "<link>") {
                        
$inlink 1;
                    } elseif(
$str == "</link>") {
                        
$inlink 0;
                    } elseif(
$str == "<name>") {
                        
$inname 1;
                    } elseif(
$str == "</name>") {
                        
$inname 0;
                    } elseif(
$str == "<textinput>") {
                        
$intxtinput 1;
                    } elseif(
$str == "</textinput>") {
                        
$intxtinput 0;
/*                    } elseif(strpos($str, "<a") != false) {
                        $iturl = strtok($str, "=");                
                        $iturl = strtok("=");
                        $iturl = strtok(">");
*/                    
} else {
                        if(
$intitle) {
                            if(
$inchannel$chtitle $str;
                            elseif(
$initem$ittitle .= $str;
                            elseif(
$intxtinput$tititle $str;
                        } elseif(
$inlink) {
                            if(
$inchannel$churl $str;
                            elseif(
$initem && $iturl == ""$iturl $str;
                            elseif(
$intxtinput$tiurl $str;
                        } elseif(
$inname) {
//                            echo ("$str<BR>\n");
                            
if($intxtinput$tiname $str;
                            elseif(
$initem$ittitle .= $str;
                        }
                    }
                }
                if(
$maxitems && $itemcount >= $maxitems) break;
                if (
$header_passed == 0) {
                    
$str ltrim(Chop(fgets($fpread$linelengh)));

                    if(
strstr($str"Last-Modified") != "") {
                        
$elts split(" "$str);
                        
// $filedate = strstr($str, " ");
                        
$filedate "$elts[2]&nbsp;$elts[3]&nbsp;$elts[4] $elts[5]&nbsp;$elts[6]";
                    } elseif(
strstr($str"Content-Length") != "") {
                        
$str strstr($str" ");
                        
$filesize = (int) $str;
                        if(
$filesize == 0) {                            
                            
writeHeader($cfile$hostname"http://" $hostname,
                                        
"http://" $hostname ":" $port $uri);
                            break;
                        }
                    } elseif (
$str == "") {
                        
$header_passed 1;
                    }
                }
            }

            if(
$tiurl != "") {
                
writeTextInput($cfile$tititle$tiname$tiurl);
            }

            if(
$filedate == "") {
                
$ctime fileMtime($cache);
                
$filedate Date("G:i m/d/y"$ctime);
            }

            if(
$itemcount == 0) {
                
fputs($cfile"No items found!<BR>");
                
$uncache 1;
            }

            
finishNews($cfile$filedate$tiurl);

            
fclose($fpread);
        }

        
fclose($cfile);

        
$comment "";

    }

    include 
$cache;
    
writeFooter($comment);

    if(
$uncache) {
        
unlink($cache);
    }

    unset(
$header_passed);
    unset(
$cache);
    unset(
$comment);

    unset(
$ctime);
    unset(
$ntime);
    unset(
$dtime);

    unset(
$uncache);
    unset(
$linelengh);
    unset(
$filedate);
}

?>

The syntax highlighted source is automatically generated by PHP from the plaintext script.
If you want to see the source of this page, have a look here.