PHP lacks built in functionality for an interactive Shell such as built into Python, Perl etc. You can execute PHP from the shell using the php -r but it isn't interactive. Using php -a didn't work for me on both Win and Linux, so I wrote this single line PHP script that will allow an "interactive" PHP Shell.
#!/usr/bin/php <?php while (1) { fputs(STDOUT, "\n\-PHP$ "); eval(trim(fgets(STDIN))); } ?>There it is on 1 line, plus the Shebang. To use it just copy the code and save to a file. You don't need to give the file an extension. For example I named it iphp. Then you execute it in the shell using ./iphp. You should get $PHP as your prompt:
-bash-3.00$ ./iphp $PHPNow you type in your PHP commands such as:
-bash-3.00$ ./iphp $PHP $result = 1+1; $PHP echo $result; 2 $PHPNotice how you can save a variable, and reference it later. This is the same for a mysql connection, file pointer etc.
When you're done, just type in exit;.
-bash-3.00$ ./iphp $PHP $result = 1+1; $PHP echo $result; 2 $PHP exit; bash-3.00$
Update: April 16, 2008
In further tests:
php -ainto the shell on Linux (Ubuntu 7.05) running PHP 5.2.4-2 (cli) works and takes you into interactive mode. I had previously tested this with PHP 5.1.6 (cli) on Linux (CentOS 3.9 and 4.6) and couldn't get it to work. The same with PHP4 and PHP5 (cli and module) on Windows.