Forum Moderators: coopster
here is the code. im a bit new and dont really know much. thanks.
pepper
____________________________________________________________________
<?php
/*
* PEPPBOT
* Written By Zack Ruddle
*/
//Open socket to server,port
$socket = fsockopen("199.xx.xx.xx",6667);
//Sends USER HOSTNAME IDENT :REAL NAME
fputs($socket,"USER Peppbot\n");
//Sends the NICK to server
fputs($socket,"NICK Peppbot\n");
//Join #lamerchan
fputs($socket,"JOIN #austinprime\n"
$commands = array(
"!version",
"!say",
"!exit",
);
//Sends the script into an infinite loop
while (1) {
//Recieves the data into $data in 128 bytes.
while ($data,fgets($socket,128)) {
//puts the data in an array by word
$get = explode(' ', $data)
//Server Pinged us lets reply! //The following code sets $nick and $chan variables from the text last entered in the channel //This is where we start processing the commands we entered in earlier //Flush it out to the browser [1][edited by: eelixduppy at 2:08 am (utc) on May 22, 2009]
if ($get[0] == "PING") {
fputs ($socket, "PONG ".$get."\n");
}
if (substr_count($get[2],"#")) {
$nick = explode(':',$get[0]);
$nick = explode('!',$nick[1]);
$nick = $nick[0];
$chan = $get[2];
$num = 3;
if ($num == 3) {
$split = explode(':',$get[3],2);
$text = $split[1];
if (in_array(rtrim($text),$commands)) {
switch(rtrim($text)) {
case "!version":
fputs($socket,"PRIVMSG $chan : www.example.com PHP IRC Bot Tutorial\n");
break;
case "!say":
$arraysize = sizeof($get);
//1,2,3 are just nick and chan, 4 is where text starts
$count = 4;
while ($count <= $arraysize) {
$saytext = $saytext." ".$get[$count];
$count++;
}
fputs($socket,"PRIVMSG ".$get[2]." :".$saytext."\n");
unset($saytext);
break;
//Shows the text in the browser as Time - Text
echo nl2br(date('G:i:s')."-".$data);
flush();
[edit reason] removed specifics [/edit]
Parse error: syntax error, unexpected ',' in /home/pepper77/public_html/peppbot/peppbot.php on line 28
28: while ($data,fgets($socket,128)} {
Should read... (note also the curly bracket at the end)
28: while ($data = fgets($socket,128)) { PHP Manual: while() [uk2.php.net]