Chapter 2
Chapter 2
1
Outlines
Installing PHP
2
Installing PHP
To create and run PHP scripts, you need to have a few things in place:
A computer running Web server software, such as Apache or Internet Information Server
(IIS).
The PHP server module installed on the same computer. This module talks to the Web
server software; this is the PHP engine that actually does the work of running your PHP
scripts.
If you want to build database - driven Web applications — you also need a database
server installed. Options include MySQL, PostgreSQL, and SQL Server.
3
Help with PHP
Install the Web server.
web server and database at the local host
Ø popular software package for windows is XAMPP: includes apache, mysql, php.
Ø Download for free here: https://www.apachefriends.org/
Ø How to install XAMPP for Windows : https://www.wikihow.com/Install-XAMPP-for-Windows
4
Help with PHP
Step 1: Step 2:
5
Help with PHP
Step 3: Step 4:
6
Help with PHP
Step 5: Step 6:
7
Help with PHP
Step 7: Step 8:
8
Help with PHP
Step 9: Step 10:
9
Help with PHP
Step 11:
10
Help with PHP
Step 12:
File → New
11
Writing PHP Statements
The echo statement: to display output.
Syntax:
echo “Hi”;
An echo statement says to output everything that is between the double quotes (" ").
PHP simple statements end with a semicolon (;).
Warning! - Leaving out the semicolon is a common error.
12
Writing PHP Statements
Add the PHP code to the HTML file name with .php or .phtml extension.
Add PHP code to your Web page by using tags to other tags in the HTML file.
<?php
...
PHP statements
...
?>
13
Writing Your HTML Script
You may have written a Hello World program in HTML. (save as: hello.html)
<html>
<head>
<title>Hello World HTML Program</title>
</head>
<body>
<p>Hello World!</p>
</body>
</html>
14
Writing Your First PHP Script
An example of a simple PHP file, with a PHP script that sends the text “Hello World!”. (save
as: hello.php.
<html>
<head><title>Hello World Script</title>
</head>
<body>
<h1>My first PHP page</h1>
<?php
echo "<p>Hello World!</p>";
?>
</body>
</html>
15
Running Your First PHP Script(Testing)
An example of a simple PHP file save as hello.php at:
c:/xampp/htdocs/ucsyPHP/
Run the hello.php at browser :
http://localhost/ucsyPHP/hello.php
In the browser :
My first PHP page
Hello World!
16
Documenting the Script
Comments are note that are embedded in the script itself.
PHP ignores comments.
Can embed comments in the script of anywhere.
The format for comments is as follows:
17
Example using Comments
Save as: comment.php
<html> Output:
<body> Hello World!
<?php
// This is a PHP comment line
/* This is a PHP
comment block
*/
echo "Hello World!";
?>
</body>
</html>
18
Thank You
19