php 流输出上的删除线字符

strikethrough characters on php stream output

我正在使用 php ssh2_exec 在远程 Linux 服务器上执行 ps aux 命令...启动连接的服务器是 Ubuntu 14.04 和我通信的服务器是Centos 6.6.

两个系统都已完全更新,我在 Ubuntu 系统上使用以下版本的 PHP 和 Apache:

apache2 2.4.7-1ubuntu4.5 libapache2-mod-php5 5.5.9+dfsg-1ubuntu4.11

php5 5.5.9+dfsg-1ubuntu4.11

我正在使用以下代码发送命令并捕获流:

echo '<pre>';
$stream = ssh2_exec($connection, $command);
stream_set_blocking($stream, true);
$stream_out = ssh2_fetch_stream($stream, SSH2_STREAM_STDIO);
while($line = fgets($stream_out)) {
           flush();
           echo $line."<br />";
       }
echo '</pre>';
echo '<br />';
unset($connection);

$command 定义为:$command = "ps aux |sed '/[.*]/d'";

命令运行,但返回的文本在显示远程系统上的进程 运行 时被文本破坏了...下面是正在发生的事情的图像 link .

https://www.joeman1.com/images/stikethoughtest.png

(我会张贴图片,但我是新来的,需要一些声誉 ;))。

当我在命令行上使用 php -f 时不会发生这种情况,只是在浏览器中 - IE、Firefox 和 Chrome 已经过测试。

关于如何解决这个问题有什么想法吗?如果您需要更多信息,请告诉我。

谢谢! 乔

尝试检查您的 HTML 来源。或者:

<?php
echo '<pre>';
$stream = ssh2_exec($connection, $command);
stream_set_blocking($stream, true);
$stream_out = ssh2_fetch_stream($stream, SSH2_STREAM_STDIO);
while($line = fgets($stream_out)) {
           flush();
           // convert the string to HTML Entities
           // Since you're getting data from a stream, no telling what might come out.
           echo htmlentities($line)."<br />";
       }
echo '</pre>';
echo '<br />';
unset($connection);
?>