After playing with Python recently I thought one of the most useful things was its interactive shell, where you could type in and evaluate variable expressions at the commandline. “Why doesn’t PHP have this,” I lamented, having played with php -r at the command line and finding it pretty useless. Up until now there’s been my ‘test’ folder which currently has 258 files in it.
“It does” retorted Jon, “what you need is php -a”. And lo and behold he was right, but this little insight doesn’t seem to be mentioned anywhere save one of the comments on the relevant page. If you’ve ever done a php –help to list the commandline options, the php -a found there doesn’t tell you very much.
So, all you need to do is issue a php -a at the command line (the php cli executable is generally in your path on unix systems and quite easy to add on windows), enter PHP mode by typing a <?php, enter the PHP expressions you want to evaluate, and prompt execution by hitting <ctrl-d> on unix or <ctrl-z> on windows.