PHP在命令行 [英] PHP in command line

查看:135
本文介绍了PHP在命令行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Python我可以通过键入

在终端/命令行中测试我的代码

  python 
python>打印hello world



我也想用PHP做, p>

  php 
echohello world;

它不工作..这是可能吗?我该怎么办?
在互联网上的快速搜索提供了很多结果,调用一个实际的.php文件运行。我只想测试一个句子,如果可能,而不创建文件和东西。


php -a

启动交互式PHP shell 。请注意,这需要使用 - with-readline (如果您在Mac OS X上使用捆绑的PHP,则不是这种情况)构建PHP



或者,如果你不需要一个单独的shell的交互性,使用

  php  - r'print_r(get_defined_constants());'

执行PHP代码段readline支持)。


Using Python I can test my code in the terminal / command line by typing

python 
python> print "hello world"

I would like to do this with PHP too, but when typing:

php
echo "hello world";

it does not work.. Is this possible? what should I do? A quick search on the internet gives a lot of results that call an actual .php file to run. I only want to test a single sentence if possible, without creating files and stuff.

解决方案

Try

php -a

which starts an interactive PHP shell. Be aware that this requires PHP to be built with --with-readline (which is not the case if you're using the bundeled PHP with Mac OS X e.g.).

Alternatively, if you don't require the interactivity of a separate shell, use

php -r 'print_r(get_defined_constants());'

to execute a PHP snippet (this doesn't require the readline support).

这篇关于PHP在命令行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆