I'm creating an IRC bot, and I wanted to store some functions in a different file. I reference the file in my main file with include()
and it works, but when I try to give fwrite()
a variable like so:
$data ="THIS IS DATA
";
fwrite($sock, $data);
It throws this error:
PHP Warning: feof() expects parameter 1 to be resource, null given in /home/kinz/Desktop/Eve/Eve.php on line 18
PHP Warning: fgets() expects parameter 1 to be resource, null given in /home/kinz/Desktop/Eve/Eve.php on
But when I put:
fwrite($sock, "THIS IS DATA
");
It works perfectly fine. Here is my full code:
function connect_s ($serv, $port, $nick) { $sock = fsockopen($serv, $port); fwrite($sock, "USER $nick $nick $nick :$nick
"); fwrite($socket, "NICK $nick
"); }
function write_d ($data) { fwrite($sock, $data); }
function join_c ($chan) { write_d("JOIN $chan
"); }
function get_in ($in) { for ($i = 3; $i <= count($in); $i++) { $out .= " $in[$i]"; } return trim("$out
"); }
function change_n ($nick) { write_d("NICK $nick
"); } ?>
I want to know why I can't use a variable as the second parameter in fwrite. Any help is greatly appreciated