Php 如何将shell_exec输出转换为页面?

Php 如何将shell_exec输出转换为页面?,php,Php,嗨,我是PHP新手,希望有人能帮助我 有时,已执行的shell脚本的输出可能有数百行长,这些行之间用一个(在shell脚本中替换)分隔,用于格式化html输出 所以我需要知道如何使输出分页,我在这里查看了一些其他类似的解决方案,但我无法使它们工作,因为它们做了不同的事情 $url = $_POST["website"]; $safeurl = escapeshellarg($url); #passthru("./check -n ".$safeurl); $stuff=shell_exec(".

嗨,我是PHP新手,希望有人能帮助我

有时,已执行的shell脚本的输出可能有数百行长,这些行之间用一个

(在shell脚本中替换)分隔,用于格式化html输出

所以我需要知道如何使输出分页,我在这里查看了一些其他类似的解决方案,但我无法使它们工作,因为它们做了不同的事情

$url = $_POST["website"];
$safeurl = escapeshellarg($url);
#passthru("./check -n ".$safeurl);
$stuff=shell_exec("./webcheck -n ".$safeurl);

$webFile = ($url.'.txt');
$write = $stuff;
$fh = fopen($webFile, 'w') or die("can't open file");
fwrite($fh, $write);
fclose($fh);

$fh = fopen($webFile, "r") or die("can't open file");
$frstuff=fread($fh, filesize($webFile));
fclose($fh);
echo $frstuff;

这不是最好的解决方案,但最简单的方法是使用javascript进行分页

尝试:

否则,您可以插入一个通用数据库分页脚本,并将数据库适配器更改为指向文件适配器,其中行数变为行数


编辑:提供了更好的链接

如果尝试使用带有附加参数的
exec
而不是
shell\u exec
,则可以将输出行作为数组而不是一个长字符串获取

$output = array();
exec("./webcheck -n $safeurl", $output);

// Inspect the contents of $output
var_dump($output);

然后,您可以根据需要遍历该数组(
$output
)。

您需要该文本文件,还是只是将其用作临时存储?我找到了一个更好的解决方案