Professional Documents
Culture Documents
PHP 01
PHP 01
• HTML
• Basics
• Images
• Tables
• Lists
• PHP
What is PHP?
• PHP is a programming language for programs that are run on web servers
2
HTTP request
HTTP Request
HTTP Response
HTTP request
HTTP Request
HTTP Response
HTML
HTTP request
Partypage.html
<html>
<head>
<title>Party Page</title>
</head>
<body>
Fun. Fun. Fun.
</body>
</html>
HTTP request
Partypage.html
Fun. Fun. Fun.
<html>
<head>
<title>Party Page</title>
</head>
<body>
Fun. Fun. Fun.
</body>
</html>
• The browser using the HTML file to construct the desired web page
Client Side Programming
HTTP Request
HTTP Response
• A client side program (usually JavaScript) can be included with the HTML file
HTTP Request
HTTP Response JS
HTML
• A client side program (usually JavaScript) can be included with the HTML file
HTTP Request
JS
HTTP Response JS
HTML
• A client side program (usually JavaScript) can be included with the HTML file
HTML
HTTP Response
HTML
HTTP Response
• This code is run by the server. Client just sees regular HTML
HTML
HTTP Response
• This code is run by the server. Client just sees regular HTML
HTML
HTTP Response
• This code is run by the server. Client just sees regular HTML
MySQL
• The PHP engine may also get information from a database
PHP Outputs HTML
HTTP Request
Top 10 Offers
HTML
HTTP Response
MySQL
• We must be mindful that we are writing a web page
HTML
• To work with PHP we need to know the basics of HTML so that we can
code HTML files
• HTML uses markup tags to mark the beginning and end of different
sections
</tr>
<tr>
<head>
<tr>
<td>Harry</td>
<meta charset="UTF-8">
<th>Name</th>
<td>31</td>
</tr>
</head>
</tr>
<tr>
<body>
<tr>
<td>Jane</td>
<h1>Hello world</h1>
<td>Tom</td>
<td>25</td>
</tr>
</table>
</body>
<br/>
<td>Dick</td>
</html>
<td>22</td>
• We can see how a HTML file will look on the web by opening it in a
browser
• It might work differently when viewed on the web. Many web servers, for
example, use case sensitive file names
Viewing a HTML file
HTTP Request
HTTP Response
• When using the XAMP web server we place the pages in the htdocs folder
• http://localhost/example01.html
Viewing a HTML file
• Bread
1. Bread
• Jam
2. Jam
• Butter
3. Butter
• Milk 4. Milk
Unordered List
• Bread
1. Bread
• Jam
2. Jam
• Butter
3. Butter
• Milk 4. Milk
Unordered List
<ul>
<li>Bread</li>
• Bread
<li>Jam</li> • Jam
<li>Butter</li> • Butter
<li>Milk</li>
• Milk
</ul>
Unordered List
<ol>
1. Bread
<li>Bread</li>
<li>Jam</li> 2. Jam
<li>Butter</li> 3. Butter
<li>Milk</li>
4. Milk
</ol>
no numbers in the HTML
<ol> Nested Lists
<li>Pizza • Lists may be nested
<ul>
• Is is very important to put the closing tags in the right place
<li>Hawaiian</li>
</ul> • Hawaiian
<li>Jam</li> 2. Jam
<li>Butter</li>
3. Butter
<li>Milk</li>
4. Milk
</ol>
My favourite foods are
<ul>
My Top 5 hobbies are
<li>Pizza
<ol>
<ol>
<li>Running</li>
<li>Hawaiian</li>
<li>Swimming</li>
<li>Chorizo</li>
<li>Jumping</li>
</ol>
<li>Dancing</li>
</li>
<li>Sleeping</li>
<li>Chips</li>
</ol>
<li>Apples</li>
</ul>
</ol>
1. France
• Paris
a. Champs Élysées
c. Place de la Concorde
• Rennes
2. UK
a. Rue de Soifs
Nested List Exercise
• London
• Manchester
3. Germany
• Munich
• Berlin
• Dusseldorf
Adding PHP to a HTML file
<body>
<?php
• Code between the <?php > tags is
run by the server when the page is
echo "World"
served up
>
• The file is saved with .php extension
</body>
<! DOCTYPE HTML>
<html lang = "en">
<head>
<meta charset="UTF-8">
<title>SOFT7008 Example 04</title>
</head>
<body>
<h1>Hello again world</h1>
This is a sample PHP page. But remember it's still a HTML page too.<br/>
<img src="img/cit.png" alt="CIT logo" width="50" height="50" />
<br/>
Today is
<?php
echo date('l, F dS Y.');
<h1>Hello again world</h1>
This is a sample PHP page. But remember it's still a HTML page too.<br/>
<img src="img/cit.png" alt="CIT logo" width="50" height="50" />
<br/>
Today is
<?php
echo date('l, F dS Y.');
?>
<br/>
<br/>
Seven multiplied by six is
<?php
echo(7*6);
?>