阅读量:140
在PHP中,你可以通过以下几种方式在命令行脚本中输出结果:
- 使用
echo语句:
<?php
echo "Hello, World!";
?>
- 使用
print语句:
<?php
print "Hello, World!";
?>
- 使用
printf语句:
<?php
printf("Hello, %s!", "World");
?>
- 使用
var_dump()函数:
<?php
$variable = array("foo" => "bar", "baz" => "qux");
var_dump($variable);
?>
- 使用
print_r()函数:
<?php
$variable = array("foo" => "bar", "baz" => "qux");
print_r($variable);
?>
- 使用
shell_exec()函数执行系统命令并输出结果:
<?php
$output = shell_exec('ls');
echo "$output";
?>
- 使用
file_get_contents()函数读取文件内容并输出结果:
<?php
$file_content = file_get_contents('example.txt');
echo "$file_content";
?>
这些方法都可以让你在PHP命令行脚本中输出结果。根据你的需求,可以选择合适的方法来显示信息。