Hello.php - My First PHP Script

This section provides a tutorial example on how to write the first PHP script, Hello.php, and run it with PHP CLI and PHP CGI.

Use any text editor like notepad, and enter the first PHP script, Hello.php:

Hello <?php echo "world!"; ?>

Run it with PHP CLI first:

>\php\php Hello.php
Hello world!

Then run it with PHP CGI:

>\php\php-cgi Hello.php
X-Powered-By: PHP/7.0.2
Content-type: text/html; charset=UTF-8

Hello world!

As expected, both versions of the PHP engine worked nicely. PHP CGI version did generate the HTTP response header for me.

But note that the "Content-type" in PHP 7.0 is set to "UTF-8", which is different than PHP 5.6. See output from PHP 5.6:

>\php5.6\php-cgi Hello.php
Content-type: text/html
X-Powered-By: PHP/5.6.6

Hello world!

Last update: 2016.

Table of Contents

 About This Book

Introduction and Installation of PHP 7.0

 What Is PHP?

 Downloading and Installing PHP 7.0 for Windows

 "php -help" - Command Line Options

 "php -m" - Built-in Modules

 "php -i" - PHP Engine Information

 php.ini - PHP Runtime Configuration

Hello.php - My First PHP Script

 Downloading and Installing PHP Documentation

 PHP Script File Syntax

 PHP Data Types and Data Literals

 Variables, References, and Constants

 Expressions, Operations and Type Conversions

 Conditional Statements - "if" and "switch"

 Loop Statements - "while", "for", and "do ... while"

 Function Declaration, Arguments, and Return Values

 Arrays - Ordered Maps

 Configuring and Sending out Emails

 Retrieving Information from HTTP Requests

 Creating and Managing Sessions in PHP Scripts

 Sending and Receiving Cookies in PHP Scripts

 Controlling HTTP Response Header Lines in PHP Scripts

 MySQL Server Connection and Access Functions

 Functions to Manage Directories, Files and Images

 SOAP Extension Function and Calling Web Services

 SOAP Server Functions and Examples

 Localization Overview of Web Applications

 Using Non-ASCII Characters in HTML Documents

 Using Non-ASCII Characters as PHP Script String Literals

 Receiving Non-ASCII Characters from Input Forms

 "mbstring" Extension and Non-ASCII Encoding Management

 Managing Non-ASCII Character Strings with MySQL Servers

 Introduction of Class and Object

 Integrating PHP with Apache Web Server

 Outdated Tutorials

 References

 PDF Printing Version