Home  >  Article  >  Backend Development  >  php cli php in command line

php cli php in command line

WBOY
WBOYOriginal
2016-07-30 13:30:03831browse

Resource: http://php-cli.com/php-cli-tutorial.shtml

Write a php file

<code><span>sudo</span> vim /var/www/html/a.php</code>

Write interpreter at the beginning of the file

<code>#!/usr/bin/php
<span><span><?php</span><span>include</span>(<span>'...'</span>); <span>/*we can include orther *.php */</span><span>echo</span> `ls -al`; <span>/* exe the linux command with `` */</span><span>?></span></span></code>

Change the permissions and run directly

<code>-<span>>sudo chmod <span>777</span> /var/www/html/a.php  
</span>-<span>>./a.php   </span></code>

tips

Some functions and statements are specially designed for PHP-CLI scripts
Waiting for command line input: $name = fgets(STDIN); //The program is paused here, waiting for input
echo getcwd() .”/n”; //Get the current script path

Copyright statement: Knowledge comes from the people, and is used by the people! Reprinting is welcome. Please attach a link to this article at the beginning. The article will be updated from time to time!

The above introduces php in the php cli command line, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn