繁体   English   中英

PHP:将多行命令行输出输出为不同的行

[英]PHP: Output multiple line command-line outputs as different lines

PHP:将多行命令行输出输出为不同的行。 抱歉,标题很难理解。 基本上,我希望我的输出像A,而不是B。目前看起来像B。我尝试了nl2br。 我尝试运行的脚本是:

脚本:

echo "Virus Scan Results:";
$scanme = system('cd /var/www/upload/files; clamscan --remove=yes '.$furl);
printf(nl2br($scanme));

A:

802931t_e_s_t.txt: OK 
----------- SCAN SUMMARY ----------- 
Known viruses: 574585 
Engine version: 0.95.1 
Scanned directories: 0 
Scanned files: 1 
Infected files: 0 
Data scanned: 0.00 MB 
Data read: 0.00 MB (ratio 0.00:1) 
Time: 2.352 sec (0 m 2 s) 
Time: 2.352 sec (0 m 2 s)

B:

802931t_e_s_t.txt: OK ----------- SCAN SUMMARY ----------- Known viruses: 574585 Engine version: 0.95.1 Scanned directories: 0 Scanned files: 1 Infected files: 0 Data scanned: 0.00 MB Data read: 0.00 MB (ratio 0.00:1) Time: 2.352 sec (0 m 2 s) Time: 2.352 sec (0 m 2 s)

为什么在命令行上使用nl2br?

nl2br输出<br />换行标记...在命令行上没有意义

编辑

两件事情:

1尝试

system('cd /var/www/upload/files; clamscan --remove=yes '.$furl, $scanme);

2您可能要使用exec函数而不是系统

例如

exec('cd /var/www/upload/files; clamscan --remove=yes '.$furl, $scanme);
$scanme = implode("\n",$scanme);

exec(字符串$ command [,数组&$ output [,int&$ return_var]])

您是否尝试过仅直接打印命令的输出?

echo "Virus Scan Results:";
echo exec('cd /var/www/upload/files; clamscan --remove=yes '.$furl);

PS。 您确实应该这样清理输入内容(如果尚未这样做的话):

$furl = escapeshellarg($furl)

escapeshellarg() -转义要用作shell参数的字符串

如果您在命令行上运行,则换行符在Windows环境中表示为'\\ n'或'\\ r \\ n'。 因此,请确保每行的末尾都有一个\\ n,并且应该获得所需的输出。 编辑:
汤姆:糟糕。 固定。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM