<?php 
// IRC-Connect 
// written by zachera [2010-02-06] 
// released under GPL license 
$IRC-Connect = new IRC-Connect('127.0.0.1',6667); 
class 
IRC-Connect 
    public 
$socket

    public function 
__construct($server,$port){ 
        
// use ssl:// for SSL connections 
        
$this->socket stream_socket_client("tcp://".$server.":".$port); 

        
// this would produce admin@[host] * zws in whois 
        
$this->__write("USER admin 0 * :zws"); 
        
$this->__write("NICK zws"); 

        
// +p = private (hide channels) 
        
$this->__write("MODE zws +p"); 

        
// join some random channel 
        
$this->__write("JOIN #help"); 

        
// lastly, read the socket 
        
$this->__read(); 
    } 

    
// read the socket 
    
public function __read(){ 
        while((
$buffer fread($this->socket1024)) !== false){ 
            
// handle buffer stuff... 

            // reply to pings to prevent getting disconnected 
            
if(preg_match("/^PING :(.+)/",$buffer,$pong)){ 
                
$this->__write("PONG :".$pong[1]); 
            } 
        } 
    } 

    
// write to the socket 
    
public function __write($str){ 
        
fwrite($this->socket,$str."\r\n"); 
    } 

?>