Forum Moderators: coopster

Message Too Old, No Replies

Parse error: syntax error, unexpected T VARIABLE

         

pepper778

1:47 am on May 22, 2009 (gmt 0)

10+ Year Member



i am getting this error Parse error: syntax error, unexpected T_VARIABLE

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!
if ($get[0] == "PING") {
fputs ($socket, "PONG ".$get."\n");
}

//The following code sets $nick and $chan variables from the text last entered in the channel
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];

//This is where we start processing the commands we entered in earlier
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 it out to the browser
flush();

[1][edited by: eelixduppy at 2:08 am (utc) on May 22, 2009]
[edit reason] removed specifics [/edit]

g1smd

1:53 am on May 22, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It would help to specify the LINE NUMBER where the error occurred and then look at that line and a few either side of it.

That said, these lines need a semi-colon at the end:

fputs($socket,"JOIN #austinprime\n"
$get = explode(' ', $data)

[edited by: g1smd at 1:57 am (utc) on May 22, 2009]

pepper778

1:55 am on May 22, 2009 (gmt 0)

10+ Year Member



haha wow ofc its line 18 (i knew i was forgetting something, sorry)

g1smd

1:58 am on May 22, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



For the line
"!exit",

remove that final comma.

pepper778

2:02 am on May 22, 2009 (gmt 0)

10+ Year Member



okay now im getting it on line 25

pepper778

2:04 am on May 22, 2009 (gmt 0)

10+ Year Member



not 25

Parse error: syntax error, unexpected ',' in /home/pepper77/public_html/peppbot/peppbot.php on line 28

pepper778

2:25 am on May 22, 2009 (gmt 0)

10+ Year Member



that line looks like this

24: //Sends the script into an infinite loop
25: while (1) {
26:
27: //Recieves the data into $data in 128 bytes.
28: while ($data,fgets($socket,128)} {
29:
30: //puts the data in an array by word
31: $get = explode(' ', $data);

eeek

6:48 am on May 22, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



fputs($socket,"JOIN #austinprime\n"

What's that?

penders

7:44 am on May 22, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



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]

penders

8:49 am on May 22, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



fputs($socket,"JOIN #austinprime\n"

What's that?

I assume that has already been 'fixed'...?

fputs($socket,"JOIN #austinprime\n");