Slide 01-3 - Introduction To PHP

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Vietnam and Japan Joint ICT HRD Program

Objectives
To understand what PHP is and how a PHP sc ipt works script o ks with ith a Web Browser B o se and a Web Server To learn what software and components you need to get started with PHP

ICT 5 Web Development

Lesson 11-3. Introduction to PHP


Nguyen Thi Thu Trang
trangntttrangntt [email protected]

To create and run a simple PHP script

Content
1. What is PHP? 2. Develop and publish PHP scripts 3. PHP proper syntax 4. PHP comments

Content
1. What is PHP? 2. Develop and publish PHP scripts 3. PHP proper syntax 4. PHP comments

1. What is PHP?
Advantages

How PHP Pages are Accessed and Interpreted


Your PC
(Internet connected) 1. Web Browser Please Enter A Phone Number Submit Erase

of Using PHP to enhance

WebServer
(Internet connected)

Web pages: pages:


Easy to use Open source Multiple platform
What

2. Se n

d Req uest

for PH P

file

Web Server Software


3. Receive request, find file and read it. 4. Execute PHP statements

7. Web Browser Web Browser Phone Query Results: That is John Doe's Phone Number

about JSP & Servlet, ASP.NET?


5

5. Send results back.

nR etur 6. R

lts esu

Content
1. What is PHP? 2. Develop and publish PHP scripts 3. PHP proper syntax 4. PHP comments

2. Develop and publish PHP script


To develop p and p publish PHP scripts p all y you need is:
A Web server with PHP built into it A client machine with a basic text editor and Internet connection FTP or Telnet software

Exploring the Basic PHP Development Process


The basic steps p y you can use to develop p and publish PHP pages are:
1. Create a PHP script file and save it to a local disk. 2. Use FTP to copy the file to the server. 3. Access your file using a browser.

Creating a PHP Script File and Saving It to a Local Disk


You can use a number of different editors to create your PHP script files.
The PHP script starts with a <?php tag and ends with ?>. Between these tags is a singlePHP print statement.

10

Alternative PHP Delimiters

Copying Files To A Web Server with FTP


1. Connect to the Internet and start FTP. 2. 2 Connect C t to t your Web W b server with ith FTP. FTP 3. Copy files to the Web server.

You can alternatively start your PHP scripts with ith th the < <script> i t> t tag as f follows: ll
<script language="PHP"> print ("A simple initial script"); </script>

If have short_open_tag enabled in its configuration fi ti fil file, you can use <? ? and d ?>. ? If asp_tags is enabled in the PHP configuration file, you can use <% and %> as delimiters.

11

12

Accessing Your File Using a Browser

Content
1. What is PHP? 2. Develop and publish PHP scripts 3. PHP proper syntax 4. PHP comments

13

14

3. Proper Syntax
If you have a syntax error then you have written one or more PHP statements that are grammatically incorrect in the PHP language. The print statement syntax:

Enclose message in quotation marks print ( "Your message to print" ); Message to Output Parenthesis are optional End in a semi-colon

If Use Improper Syntax


Suppose pp

y you use the wrong g syntax: y

1. <?php 2. print ( A simple initial script); 3. ?>

15

16

A Little About PHP's Syntax


Some

Embedding PHP Statements Within HTML Documents


One

PHP Syntax Issues:

Be careful to use quotation marks, parentheses, and brackets in pairs. Most PHP commands end with a semicolon (;). Be careful of case. PHP ignores blank spaces.

way to use PHP is to embed PHP scripts within HTML tags in an HTML document.

17

1. <html> 2. <head> 3. <title>HTML With PHP Embedded</title> </head> 4. <body> y 5. <font size=5 color=blue>Welcome To My Page</font> 6. <?php 7. print ("<br> Using PHP is not hard<br>"); 8. ?> 9. and you can learn to use it quickly! 10. </body></html>

18

Would Output The Following ...

Using Backslash ( (\ \) to Generate HTML Tags with print()

Sometimes you want to output an HTML tag th t also that l requires i double d bl quotation t ti marks. k
Use the backslash ( (\ \) character to signal that the double quotation marks themselves should be output: output:

print ("<font color=\ color=\"blue "blue\ \">"); The Th above b statement t t t would ld output: t t <font color="blue">

19

20

Content
1. What is PHP? 2. Develop and publish PHP scripts 3. PHP proper syntax 4. PHP comments

4. PHP Comments
Comments

enable you to include descriptive text along with the PHP script
Comment lines are ignored when the script runs; they do not slow down the runrun-time. Comments have two common uses.
Describe Describe

the overall script purpose. particularly tricky script lines.


22

21

Using Comments with PHP Scripts


Comment

Example Script with Comments


1. <html> <head> 2. 2 <title> Generating HTML From PHP</title> </head> 3. <body> <h1> Generating HTML From PHP</h1> 4. <?php 5. // 6. // Example script to output HTML tags 7. // 8. print ("Using ( Using PHP has <i>some advantages:</i>"); advantages:</i> ); 9. print ("<ul><li>Speed</li><li>Ease of use</li> <li>Functionality</li></ul>"); //Output bullet list 10. print ("</body></html>"); 11. ?>
23 24

Syntax - Use //

<?php // This is a comment ?>


Can

place on Same line as a statement:


<?php //Output a line print ("A simple initial script"); ?>

Alternative Comment Syntax

Question?

PHP allows a couple of additional ways to create comments. comments


<?php phpinfo(); # This is a builtbuilt-in function ?>

Multiple line comments.


<?php /* A script that gets information about the PHP version being used. */ phpinfo(); ?>
25 26

You might also like