【问题标题】:PHP exec() clear outputPHP exec() 清除输出
【发布时间】:2015-03-24 07:13:21
【问题描述】:

我有一个包含以下代码的 PHP 文件 (file.php):

<?php
exec("program.exe command",$output);
print_r($output);
?>

当 file.php 在浏览器中打开时,它会打印以下输出:

"Array ( [0] => my_output ) "

我只想打印“my_output”。不是“Array ([0] =&gt;”部分。怎么做?

【问题讨论】:

  • print_r 用于打印数组,这就是您获得该输出的原因。改用echo($output[0])

标签: php arrays output exec


【解决方案1】:

例子:

// Correct
print $arr['fruit'];  // apple
print $arr['veggie']; // carrot

print $arr['fruit'];  // apple

试试这个代码:

<?php
exec("program.exe command",$output);
echo $output[0];
?>

阅读更多关于数组的内容:

http://php.net/manual/en/book.array.php

http://php.net/manual/en/language.types.array.php

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-09
    • 1970-01-01
    相关资源
    最近更新 更多