2
我試圖構建一個php腳本,它連接到telnet服務器並運行一些命令。當使用fsockopen時將php輸出保存到變量
我想將命令的返回輸出保存到變量中。
例如: 命令:給我一個數字! 服務器返回一個數字..可以說它是100. 我想將數字100保存爲變量。
這裏是我的源代碼:
<?php
# connecting
$fp=fsockopen("10.73.xxx.xxx",23);
# login
fputs($fp,"\r");
sleep(1);
fputs($fp,"user\r");
sleep(1);
fputs($fp,"password\r");
# commands
fputs($fp,"give me a number!\n"); //this returns the number I would like to save as variable
sleep(1);
fclose($fp);
?>