slide 01-3 - introduction to php

Upload: linh-barbie

Post on 03-Apr-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/29/2019 Slide 01-3 - Introduction to PHP

    1/7

    1

    Vietnam and Japan JointVietnam and Japan Joint

    ICT HRD ProgramICT HRD Program

    ICT 5 Web DevelopmentICT 5 Web Development

    Lesson 1Lesson 1--3. Introduction to PHP3. Introduction to PHP

    NguyenNguyen ThiThi ThuThu TrangTrang

    [email protected]@mail.hut.edu.vn

    ObjectivesObjectives

    To understand what PHP is and how a PHPTo understand what PHP is and how a PHPscr p wor s w a e rowser an ascr p wor s w a e rowser an aWeb ServerWeb Server

    To learn what software and componentsTo learn what software and components

    you need to get started with PHPyou need to get started with PHP

    22

    ContentContent

    1.1. What is PHP?What is PHP?

    2.2. Develop and publish PHP scriptsDevelop and publish PHP scripts

    3.3. PHP proper syntaxPHP proper syntax

    4.4. PHP commentsPHP comments

    33

    ContentContent

    1.1. What is PHP?What is PHP?

    2.2. Develop and publish PHP scriptsDevelop and publish PHP scripts

    3.3. PHP proper syntaxPHP proper syntax

    4.4. PHP commentsPHP comments

    44

  • 7/29/2019 Slide 01-3 - Introduction to PHP

    2/7

    2

    1. What is1. What is PHP?PHP?

    Advantages of Using PHP to enhanceAdvantages of Using PHP to enhance

    Web pagesWeb pages::

    Easy toEasy to useuse

    OpenOpen sourcesource

    What about JSP & Servlet,What about JSP & Servlet,

    ASP.NET?ASP.NET?

    55

    How PHP Pages are Accessed andHow PHP Pages are Accessed and

    InterpretedInterpretedour

    (Internet connected)

    e erver(Internet connected)

    2.SendRequestforPHPfilePlease EnterAPhoneNumber

    Submit Erase

    1. Web Browser Web ServerSoftware

    3. Receive

    request, findfile and read it.

    4. ExecutePHP

    statements

    6.Retur

    nResu

    lts

    Web Browser

    Phone QueryResults:

    That isJohn Doe'sPhone

    Number

    7. Web Browser 5. Sendresultsback.

    66

    ContentContent

    1.1. What is PHP?What is PHP?

    2.2. Develop and publish PHP scriptsDevelop and publish PHP scripts

    3.3. PHP proper syntaxPHP proper syntax

    4.4. PHP commentsPHP comments

    77

    2. Develop and publish PHP script2. Develop and publish PHP script

    To develo and ublish PHP scri ts all ouTo develo and ublish PHP scri ts all ou

    need is:need is:

    A Web server with PHP built into itA Web server with PHP built into it

    A client machine with a basic text editor andA client machine with a basic text editor and

    FTP or Telnet softwareFTP or Telnet software

    88

  • 7/29/2019 Slide 01-3 - Introduction to PHP

    3/7

    3

    Exploring the Basic PHPExploring the Basic PHP

    Development ProcessDevelopment Process

    The basic ste s ou can use to develoThe basic ste s ou can use to develo

    and publish PHP pages are:and publish PHP pages are:

    1. Create a PHP script file and save it to a local disk.1. Create a PHP script file and save it to a local disk.

    2. Use2. Use FTPFTP to copy the file to the server.to copy the file to the server.

    3. Access your file using a browser.3. Access your file using a browser.

    99

    Creating a PHP Script File and Saving ItCreating a PHP Script File and Saving It

    to a Local Diskto a Local Disk

    You can use a number of different editorsYou can use a number of different editorsto create your PHP script files.to create your PHP script files. The PHP script starts with a .?>.

    Between these tags is a singlePHP print statement.Between these tags is a singlePHP print statement.

    1010

    Alternative PHP DelimitersAlternative PHP Delimiters

    You can alternatively start your PHP scriptsYou can alternatively start your PHP scriptsw e scr p ag as o ows:w e scr p ag as o ows:

    print ("A simple initial script");print ("A simple initial script");

    If haveIf have short_open_tagshort_open_tag enabled in itsenabled in its

    con gura on e, you can use < an >.con gura on e, you can use < an >.

    IfIfasp_tagsasp_tags is enabled in the PHPis enabled in the PHP

    configuration file, you can use configuration file, you can use as delimiters.as delimiters.

    1111

    Copying Files To A WebCopying Files To A WebServer with FTPServer with FTP

    1. Connect to the Internet and start FTP.1. Connect to the Internet and start FTP.

    . onnec o your e server w .. onnec o your e server w .

    3. Copy files3. Copy files

    to the Webto the Webserver.server.

    1212

  • 7/29/2019 Slide 01-3 - Introduction to PHP

    4/7

    4

    Accessing Your File Using aAccessing Your File Using a

    BrowserBrowser

    1313

    ContentContent1.1. What is PHP?What is PHP?

    2.2. Develop and publish PHP scriptsDevelop and publish PHP scripts

    3.3. PHP proper syntaxPHP proper syntax

    4.4. PHP commentsPHP comments

    1414

    3. Proper3. Proper SyntaxSyntax

    If you have a syntax error then you haveIf you have a syntax error then you havewritten one or more PHP statements that arewritten one or more PHP statements that aregrammatically incorrect in the PHP language.grammatically incorrect in the PHP language.

    TheThe printprint statement syntax:statement syntax:Enclose message

    in quotationmarks

    End in asemi-colon

    print ( "Your message to print" );

    Message to Output

    Parenthesis areoptional

    1515

    If Use Improper SyntaxIf Use Improper Syntax

    Suppose you use the wrong syntax:Suppose you use the wrong syntax:

    1. 3. ?>

    1616

  • 7/29/2019 Slide 01-3 - Introduction to PHP

    5/7

    5

    A Little About PHP's SyntaxA Little About PHP's Syntax

    Be careful to use quotation marks, parentheses,Be careful to use quotation marks, parentheses,

    and brackets in pairs.and brackets in pairs.

    Most PHP commands end with a semicolon (;).Most PHP commands end with a semicolon (;).

    Be careful of case.Be careful of case.

    PHP ignores blank spaces.PHP ignores blank spaces.

    1717

    Embedding PHP StatementsEmbedding PHP StatementsWithin HTML DocumentsWithin HTML Documents

    One way to use PHP is to embed PHPOne way to use PHP is to embed PHPscripts within HTML tags in an HTMLscripts within HTML tags in an HTMLdocument.document.

    1.1.

    2.2.

    3.3.HTML With PHP Embedded HTML With PHP Embedded

    4.4.5.5.Welcome To My PageWelcome To My Page

    6.6.?>

    9.9.and you can learn to use it quickly!and you can learn to use it quickly!

    10. 10. 1818

    Would Output The Following ...Would Output The Following ...

    1919

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

    Sometimes you want to output an HTML tagSometimes you want to output an HTML taga a so requ res ou e quo a on mar s.a a so requ res ou e quo a on mar s.

    Use the backslash (Use the backslash (\\) character to signal that) character to signal that

    the double quotation marks themselves shouldthe double quotation marks themselves shouldbe outputbe output::

    print ("");">");

    e a ove s a emen wou ou pu :e a ove s a emen wou ou pu :

    2020

  • 7/29/2019 Slide 01-3 - Introduction to PHP

    6/7

    6

    ContentContent1.1. What is PHP?What is PHP?

    2.2. Develop and publish PHP scriptsDevelop and publish PHP scripts

    3.3. PHP proper syntaxPHP proper syntax

    4.4. PHP commentsPHP comments

    2121

    4. PHP Comments4. PHP Comments

    Comments enable you to includeComments enable you to includedescriptive text along with the PHPdescriptive text along with the PHPscriptscript

    Comment lines are ignored when theComment lines are ignored when thescript runs; they do not slow downscript runs; they do not slow down

    the runthe run--time.time.Comments have two common uses.Comments have two common uses.

    Describe the over all script purpose.Describe the over all script purpose.

    Describe particularly t ricky script lin es.Describe particularly t ricky script lin es.

    2222

    Using Comments withUsing Comments withPHP ScriptsPHP Scripts

    Comment SyntaxComment Syntax -- Use //Use //?>

    Can place on Same line as aCan place on Same line as astatement:statement:?>2323

    Example Script with CommentsExample Script with Comments

    1. 1.

    ..

    3. Generating HTML From PHP3. Generating HTML From PHP

    4. 11. ?>

    2424

  • 7/29/2019 Slide 01-3 - Introduction to PHP

    7/7

    7

    Alternative Comment SyntaxAlternative Comment Syntax PHP allows a couple of additional ways toPHP allows a couple of additional ways to

    ..?>

    Multiple line comments.Multiple line comments.

    /* A script that gets information about/* A script that gets information about

    the PHP version being used. */the PHP version being used. */

    phpinfo(); ?>phpinfo(); ?>

    2525

    Question?Question?

    2626