Ways to enter and run a PHP snippet (no PHP file required) in the Windows command-line window

Source: Internet
Author: User
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.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.