我是一名PHP新手,在一個IRC bot上工作,它加入一個頻道,發送一條消息,然後退出。我怎樣才能打破這個PHP while循環?
除了發送$ message之外,一切都在腳本中工作(第6行),我不明白如何退出無限循環。
// Open Internet connection
$socket = fsockopen("$server", $port);
fputs($socket,"USER $nick $nick $nick $nick :$nick\n");
fputs($socket,"NICK $nick\n");
fputs($socket,"JOIN ".$chan."\n");
fputs($socket, "PRIVMSG ".$chan." :$message1\n");
// Begin while loop
while(1) {
while($data = fgets($socket)) {
echo nl2br($data);
flush();
$ex = explode(' ', $data);
$channel = $ex[2];
$nicka = explode('@', $ex[0]);
$nickb = explode('!', $nicka[0]);
$nickc = explode(':', $nickb[0]);
// $host = $nicka[1];
$nick = $nickc[1];
if($ex == "PING"){
fputs($socket, "PONG ".$ex[1]."\n");
}
$args = NULL; for ($i = 4; $i < count($ex); $i++) { $args .= $ex[$i] . ' '; }
}
}
爲什麼你有兩個循環呢? – Jeff
'break 2;'也許? – bishop