Interpret PHP as you type | PHP prompt

How to Code PHP from the prompt.

How to run PHP in interactive mode.

Open a command line prompt and type the following:

C:\> php -a

Interactive shell

php > echo 5+8;

ctrl-D to exit

If it can't find PHP, you need to check and see if it is installed or if PHPs home directory is in your operating system's PATH variable. Also you need the CLI SAPI installed inorder to run phpin this manner.

This is a great way to isolate your PHP syntax for rapid testing while you are working in a larger environment.

Notice at the top after you run the command the words "Interactive Shell", this is not the same as "Interactive Mode". Interactive mode works like the following:

C:\> php -a

Interactive mode enabled

echo 9+20;
X-Powered-By: PHP/5.1.2
Content-type: text/html


Ininteractive mode PHP was not compiled with readline support. Everytime you hit enter or ctrl-D it tries to interpret what you typed.

You can also check 'php -m' and see if readline is listed in the output.

In Linux Interactive mode is like running PHP with stdin as the file input. You just type code, and when you're done (Ctrl-D or Enter), PHP executes whatever you typed.

comments powered by Disqus