I\'m running php interactively from xampp (5.4.7) on my Win 7 machine and cannot get any output from the window. I searched around various solutions and nothing so far has
To use in windows. Ensure you have a PATH variable to php directly in your windows environment. May require restart. Use gitbash/cmd/rails shell/nodejs etc. but shouldn't make any difference. Open cmd
Check php with command: php -v if all good populates the php version etc etc
load interactive mode with: php -a enter your code once enabled, for example as follows (each line has carriage return) the ^z is the shell output of pressing the ctrl key and the z key together this runs your small snippet but instantly pops you out of php interactive mode
<?php
$x = 5;
$y = 6;
$z = $x + $y;
echo $z;
?>
^z
(will return 11) was really good at maths ha:-)
The first line I type after entering php -a
is slightly different to yours:
<?php //press Enter
echo 'This '; //press Enter
echo 'works'; //press Enter
//Press Ctrl+z on this line to get a ^Z, then press Enter
This works
C:\Windows\System32>
The nuisance is that it returns to the Windows command prompt and you have to keep typing php -a and <?php before you can type more.
To save a bit of typing I created a shortcut, right-clicked it, opened its Properties dialog and entered the following command in the Target text box:
C:\Windows\System32\cmd.exe /k "php -a"
This shortcut opens a PHP prompt in interactive mode. Alternatively, this one starts in interactive mode and lists the PHP switches:
C:\Windows\System32\cmd.exe /k "php -h & php -a"