在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 "<pre>$output</pre>"; ?>
file_get_contents()
函数读取文件内容并输出结果:<?php $file_content = file_get_contents('example.txt'); echo "<pre>$file_content</pre>"; ?>
这些方法都可以让你在PHP命令行脚本中输出结果。根据你的需求,可以选择合适的方法来显示信息。