Posts Tagged ‘PHP’
-
Hello, PHP World!
Posted on 2月 8th, 2012 by cx20
PHP
PHP は Web サーバー上で動作するサーバーサイドスクリプト言語である。
CGI 版およびモジュール版(Apache や IIS の拡張モジュールとして動作)が存在する。
PHP の類似技術としては、ASP、ASP.NET、Java Servlet、JSP(JavaServer Pages) 等がある。
ソースコード(CGI 版)
#!/usr/bin/php <html> <head> <title>Hello, World!</title> </head> <body> <p><?php echo "Hello, PHP World!"; ?></p> </body> </html>
ソースコード(モジュール版)
<html> <head> <title>Hello, World!</title> </head> <body> <p><?php echo "Hello, PHP World!"; ?></p> </body> </html>
実行方法(CGI 版)
1. CGI用フォルダ(cgi-bin等)に配置 2. 実行権限の付与 $ chmod +x hello.php 3. ブラウザで表示 http://localhost/cgi-bin/hello.php
実行方法(モジュール版)
1. Web 公開フォルダ に配置 2. ブラウザで表示 http://localhost/doc/hello.php
実行結果
Hello, PHP World!
-
Hello, PHP(CLI) World!
Posted on 12月 19th, 2011 by cx20
PHP
PHP は Web アプリケーションのサーバーサイドに特化したスクリプト言語である。
名前の由来は「Personal Home Page」から。現在は「PHP is Hypertext Pre-processer」の略とされている。
PHP の実行方式としては、サーバーモジュール方式(mod_php, ISAPI)、CGI 方式、CLI 方式などがある。
CLI 方式の場合は HTTP ヘッダ “Content-Type: text/html¥n¥n” が出力されず通常のコマンドラインアプリケーションとしての動作をする。
ソースコード
実行方法(スクリプトファイルを指定して実行)
$ php hello.php
実行方法(実行権限を付与して実行)
$ chmod +x hello.php $ ./hello.php
実行結果(CLI版として実行)
Hello, PHP World!
実行結果(CGI版として実行)
X-Powered-By: PHP/5.3.6 Content-type: text/html Hello, PHP World!