在 PHP CLI 中使用 echo?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8799204/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using echo with PHP CLI?
提问by Roman Newaza
I'm running the following script in the PHP CLI:
我在 PHP CLI 中运行以下脚本:
<?php echo 'hello world!'; ?>
Nothing shows up. How can I enable output?
什么都不显示。如何启用输出?
回答by Roman Newaza
Run it in your terminal:
在终端中运行它:
php -r 'echo "Hello World!\n";'
回答by Jonathan
It looks like you forgot the shebang line. Yours may vary depending on your setup, but you need to somehow point to php.
看起来你忘记了shebang线。您的设置可能会有所不同,但您需要以某种方式指向 php。
#!/usr/bin/env php
<?php echo 'hello world!'; ?>
回答by sebo
Make sure the user has permissions to run the file.
确保用户有权运行该文件。
回答by alex
You can use php -a (php interactive shell) :
您可以使用 php -a (php 交互式 shell) :
php -a
echo 'helloworld';