I'm trying to build a php script, which connects to a telnet server and runs a few commands.
I would like to save the returned output of a command into a variable.
Example: Command: Give me a number! The server returns a number.. lets say it is 100. I would like to save the number 100 as variable.
Here is my source code:
<?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);
?>
You probably want stream_get_line
$theData = stream_get_line($fp, 1024, "\n");
// 1024 = The maximum number of bytes to read from the handle.
// \n = string delimiter.