Sunday, July 18, 2010

how to run PHP in interactive mode

One way is to invoke the interpreter from command line like so:

php -a

That seemed to be acting up lately for me, especially in failing to display any output sent with echo.

So I was looking for an alternative replacement, which I found here, courtesy of Facebook. It has all functionality I need.

It depends on Python to be installed on your machine. Once installed you invoke it by simply typing phpsh at the command line.


Vitalie said...

Bogdan, maybe i didn't understood you correctly, but you should try php interactivity such way:

[me@neo]<~> 10
21:00 Wed Jan 23 > php -a
Interactive shell

php > echo "Hello interactive PHP!".PHP_EOL;
Hello interactive PHP!
php > echo "\nSeems to be OK!\n";

Seems to be OK!
php >

You should be noted the presence of (;) at the end of commands.

Enjoy :)

Unknown said...

@Vitalie - Thanks for your comment. It may well be the case that I wasn't putting the semicolon at the end.