To run PHP commands immediately on Terminal you can pass -a
option to your installed PHP:
php -a
Details:

php -a
opens an interactive shell which let you type directly PHP commands and view the result on your terminal, As an example, after typing php -a
in terminal you can type echo 'Hello World';
and after Press Enter Hello World!
will be printed on the screen.
Windows Solution
On windows there is no interactive mode same as Linux but still you can use interactive like mode!, So, open PHP on place you installed it for example if you use XAMPP then your PHP should be is on C:\xampp\php
(or add the binary directory to environment variables) and then type php -a
, At the end of each line you can view the results by pressing Ctrl+Z
and then Enter
.
php -a
echo 'hello world!';
^Z