php telnet fgets返回奇怪的字符

时间:2013-11-20 16:33:28

标签: php character fwrite fgets fsockopen

使用fsockopen,fwrite&我希望使用以下代码通过telnet在远程服务器上与我的帐户进行通信:

$ip = "*hosts*";
$user = "*username*";
$pass = "*password*";

$fp = fsockopen($ip, 23, $errno, $errstr, 30);
if (!$fp) 
{
    echo "$errstr ($errno)<br />\n";
    exit;
    $utilitiesObj->hardFlush();
} 
else 
{

    echo "<br >We can connect";
    echo "<br >Sending user";

    $retFromFwrite = fwrite($fp,"$user\n");
    echo "<br >ret: ".$retFromFwrite;

        $line =  fgets($fp, 1024);
        echo "<br >line: ".$line;

    echo "<br >Complete";

}
fclose ($fp);

我从上面得到的输出是:

<br >We can connect<br >Sending user<br >ret: 8<br >line: ÿý%<br >Complete

为什么我会得到奇怪的字符?当我直接通过终端登录时,这就是我进入屏幕:

login: *username*
Password:

提前致谢。

0 个答案:

没有答案