Sometimes simply to test the effect of a PHP function, always need to build a php file, copy the path of the file, and then through the Web Access or PHP command to execute the PHP file.
How do you always want to execute a PHP snippet without creating a file? Finally found the method, now share it, to the people in need.
Premise:
1. This article is only about the situation under Windows. Other operating systems are similar, but slightly different.
2. You must have PHP installed, and set the environment variables. If the downloaded executable installation package is installed, the environment variable is generally set up automatically. If the zip package is unpacked yourself, you need to set the environment variables manually.
Now say the steps to enter and run the PHP snippet in the Windows command-line window.
1. Open the Windows command-line window (there are many ways, do not understand the self-check), as follows:
2. At the command prompt, enter PHP and press ENTER, such as:
3. Enter the PHP code snippet, you can enter multiple lines of PHP code, or paste it directly in. Such as:
4. This step is critical, because it is multi-line input, how do you know that you have entered to start execution? Need to use a shortcut key.
Press Enter , press CTRL + Z (the screen will appear with a ^z character), and then press ENTER. You can see the effect of PHP running.
To make sure to press CTRL + Z when the input cursor is at the beginning of the line, that is, ^z must be in a separate row, after seeing ^z and then press ENTER to execute.
^z must be entered by pressing CTRL + Z , instead of manually entering the two characters ^ and Z.
Running results such as:
Is this a convenient way to test a small fragment of code? (If you want to open the command-line window itself is too troublesome, then ...) )
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.