Joomla!, Wordpress tips for building your site

How to use php with console (command line)

Published on| July 17th, 2009 | No Comment.

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.

> php test.php

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.

<?php
echo 'Hello World!';
?>

When you run ‘test.php’, following characters will display on command line.

> php test.php
Hello World!
>

Other , when you execute PHP from command line, you can specify the command parameters like a follows.

> php test.php --help

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’.

<?php
if ($argc == 2 &#038;&#038; in_array($argv[1], array('--help', '-help', '-h', '-?'))) {
?>
<?php echo $argv[0]; ?> --help
Display Help.
<?php
} else {
        echo 'Hello World!';
}
?>

$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.

> php test.php --help
test.php --help
 
Display help.

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. ()






Comments

Leave a Reply








Transrator

Recent Posts

Categories

Tag Cloud

execute remove フロントページ 投稿ページ トップページ install WIndows Note Convert META generator 日付 donwload file manage multibyte utf-8 unicode shiftjis euc console サイトマップ 問題 ParmaLink Redirect パーマリンク はみ出る pre テンプレート テーマ タグクラウド マルチランゲージ リダイレクト PHP(タグ) タグ table control HTML(タグ) コマンド 国際化(翻訳) SQLite(タグ) MySQL(タグ) qTranslate プラグイン(タグ) Wordpress(タグ)

Links

Site Description

Joomla!, Wordpress as CMS using a site building, site management, software usage to describe the development tips.

  • はてなブックマークへ追加する
  • Facebookでシェアする
  • twitter でつぶやく
  • Google Plusでシェアする
  • Pocketでシェアする
ページトップへ