如何在PHP交互模式下执行 [英] How to execute in PHP interactive mode

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

问题描述

我是PHP的新手,我只想在命令提示符下(交互模式)运行PHP。

I am new to PHP, and I just wanted to run PHP in a command prompt (interactive mode).

所以我输入了以下代码:

So I typed this code:

`php -v`
`<?php`
`echo 7;`
`?>`

但是我不知道如何执行它,因为当我按下 Enter cmd希望我继续编写代码。我在php.net和其他论坛上进行了搜索,但没有找到任何东西。那么是否有功能键或某些东西可以显示结果?

But I do not know how to execute it, because when I press Enter cmd expects me to continue writing the code. I searched on php.net and some other forums, but I didn't find anything. So is there a function key or something to display the result?

推荐答案

Ctrl + d 将触发文件结束条件,并导致脚本执行。

Ctrl+d will trigger an end-of-file condition and cause the script to be executed.

另请参见交互式php shell如何工作?



尽管
的名称和功能相似,但交互式Shell和交互式模式却不一样。

Interactive Shell and Interactive Mode are not the same thing, despite the similar names and functionality.

如果您键入php -a并得到 Interactive Shell的响应,然后显示php>提示符,您就有可用的交互式Shell(PHP
已使用readline支持进行编译)。相反,如果您收到
启用了交互模式的响应,则说明您没有可用的交互式外壳
,因此本文不适用于您。

If you type php -a and get a response of 'Interactive Shell' followed by a php> prompt, you have interactive shell available (PHP was compiled with readline support). If instead you get a response of 'Interactive mode enabled', you DO NOT have interactive shell available and this article does not apply to you.

因此,如果仅获得启用交互模式,则您只能输入
来输入PHP代码,然后在完成后向PHP发送EOF到
执行它。

So if you get only "Interactive mode enabled", then you'll only be able to type in PHP code and then when you're done, send PHP an EOF to execute it.

EOF表示文件结束。

"EOF" means "end-of-file".

这篇关于如何在PHP交互模式下执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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