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:

C:\herong> \php\php Hello.php

Hello world!

Then run it with PHP CGI:

C:\herong> \php\php-cgi Hello.php

X-Powered-By: PHP/7.3.0
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.3 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!

Table of Contents

 About This Book

Introduction and Installation of PHP 7.3

 What Is PHP

 Downloading and Installing PHP 7.3 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

 "php -a" - PHP Interactive Shell

 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

 Interface with Operating System

 Introduction of Class and Object

 Integrating PHP with Apache Web Server

 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

 Managing File Upload

 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

 Parsing and Managing HTML Documents

 Configuring and Sending out Emails

 Image and Picture Processing

 Managing ZIP Archive Files

 Managing PHP Engine and Modules on macOS

 Managing PHP Engine and Modules on CentOS

 Outdated Tutorials


 Full Version in PDF/EPUB