PHP停止system()输出


PHP stop system() from outputting

我有一个system()查询输出ping信息,我该如何阻止它这样做?

system('ping -c1 -w1 '.$addr, $return);

http://us3.php.net/exec

  • system():执行外部程序并显示输出
  • exec():执行外部程序
  • shell_exec():通过shell执行命令并以字符串形式返回完整的输出

使用exec(),它不会输出调用的结果。或者,如果您希望以字符串形式输出,则使用shell_exec()。

试试反勾操作符怎么样?http://www.php.net/manual/en/language.operators.execution.php

<?php
$output = `ls -al`;
echo "<pre>$output</pre>";
?>

这将把它输出成一个字符串供您随意处理。