How to use php with console (command line)
Perhaps I guess that you think that PHP language is very useful WEB language.
PHP usage is not only that.
PHP can also use from the command line.
Very famous CMS (Ex. Joomla! , WordPress etc,.) is often developed by PHP and MySQL.
I often use Joomla! and WordPress because of being developed by PHP (and open source).
So, when I have problem, I will clear problem very easy. Also it is a favor of open source.
Well, I will speak how to execute PHP with command line from now.
It is very simle.
If you want to execute PHP from command line, you will only input following characters.
|
Of course, first, you must add environment of PATH "php installation directory".
Next, you must create ‘test.php’ file.
following example of ‘test.php’ will only display characters of ‘Hello World’ on command line.
|
When you run ‘test.php’, following characters will display on command line.
|
Other , when you execute PHP from command line, you can specify the command parameters like a follows.
|
If you want to input the command parameters, you should rewrite ‘test.php’ for append functions of command parameters.
Following code is example of ‘test.php’.
|
$argc and $argv can be used with PHP as a variable reserved to the way just like C language.
$argc is count of parameters (if $argc equal 1, it means parameters is nothing.)
$argv are the parameters.
When you run ‘test.php’, following characters will display on command line.
|
You will be able to write script program very easy with PHP. Specially you will feel very easy when you write script of WEB and HTML.
I think PHP works very well.
This post is very basic PHP usage. ()
You might also like:
Comments
Leave a Reply