35
http://www.shreedhoon.com/training/index.php PHP Training in Gandhin agar Introduction to PHP http://www.shreedhoon.com

Php guide for beginner

Embed Size (px)

DESCRIPTION

We are an IT Company that's develop website,software,android,iPhone application as well as provide professional training in different course like php training, android training, iPhone training, .net training in Gandhinagar.

Citation preview

Page 1: Php guide for beginner

http://www.shreedhoon.com/training/index.php

PHP Training in Gandhinagar

Introduction to PHP

http://www.shreedhoon.com

Page 2: Php guide for beginner

PHP ReferencesPHP References General: Download, documentationGeneral: Download, documentation

http://www.php.net/ Documentation: manualDocumentation: manual

http://www.php.net/manual/en/ http://us2.php.net/manual/en/index.php

PHP.net tutorialPHP.net tutorial http://php.net/manual/en/tutorial.php

W3schools tutorialW3schools tutorialhttp://www.w3schools.com/php/default.asp

http://www.shreedhoon.com/training/index.php

Page 3: Php guide for beginner

PHP functionsPHP functions

Documented PHP functionsDocumented PHP functions http://us2.php.net/quickref.php

You can create your own functions tooYou can create your own functions too

http://www.shreedhoon.com/training/index.php

Page 4: Php guide for beginner

http://www.shreedhoon.com/training/index.php

Objectives Objectives

What is PHP?What is PHP? How does a PHP script work with a How does a PHP script work with a

Web Browser and a Web Server?Web Browser and a Web Server? What software and components you What software and components you

need to get started with PHP?need to get started with PHP?

To create and run a simple PHP scriptTo create and run a simple PHP script

Page 5: Php guide for beginner

http://www.shreedhoon.com/training/index.php

What Is PHP?What Is PHP?

PHP, PHP Hypertext PreprocessorPHP, PHP Hypertext Preprocessor Server-side scripting languages for creating Server-side scripting languages for creating

dynamic web pagesdynamic web pages

Page 6: Php guide for beginner

http://www.shreedhoon.com/training/index.php

PHP advantagesPHP advantages

Advantages of Using PHP to enhance Web Advantages of Using PHP to enhance Web

pages:pages: Easy to useEasy to use Simpler than PerlSimpler than Perl Open sourceOpen source Multiple platform.Multiple platform.

Page 7: Php guide for beginner

http://www.shreedhoon.com/training/index.php

How PHP Pages are Accessed How PHP Pages are Accessed and Interpretedand Interpreted

Client: Web browser Web server1.Form submitted with a submit button

2.----- Action sends a request to the php file in server

3. Receive the request, find the file,

and read it

4. Execute the PHP commands

5. Send the results back

6. ---- results returned as HTML file

7. Web browser renders the HTML file, displaying the results

Page 8: Php guide for beginner

http://www.shreedhoon.com/training/index.php

Getting Started with PHPGetting Started with PHP

To develop and publish PHP scripts you need: To develop and publish PHP scripts you need: A client machine with a basic text editor and A client machine with a basic text editor and

Internet connectionInternet connection• Prepare a text file with .php extensionPrepare a text file with .php extension

FTP or Telnet softwareFTP or Telnet software• Upload the file.php to the serverUpload the file.php to the server

A Web server with PHP built into itA Web server with PHP built into it• Process the file.phpProcess the file.php

Page 9: Php guide for beginner

http://www.shreedhoon.com/training/index.php

WHH NoteWHH Note

This means that a browser e.g. IE or This means that a browser e.g. IE or Firefox on the client computer will not Firefox on the client computer will not recognize or render a file with recognize or render a file with extension .phpextension .php

How do you check your PHP script before How do you check your PHP script before submission to server?submission to server?

Page 10: Php guide for beginner

http://www.shreedhoon.com/http://www.shreedhoon.com/training/index.phptraining/index.php

Getting Started with PHPGetting Started with PHPSet up development computer as a serverSet up development computer as a server

Laptop contains a server and a browser environmentLaptop contains a server and a browser environment

Laptop is also set up as a Web server - WAMPserverLaptop is also set up as a Web server - WAMPserver

• Windows Apache, MySQL, PHPWindows Apache, MySQL, PHP

Client machine: PC, XP, editors, browsersClient machine: PC, XP, editors, browsers

Internet connection not neededInternet connection not needed Use copy and paste to transfer the scriptsUse copy and paste to transfer the scripts

For class demos:For class demos: localhost or 127.0.0.1 or cs346 serverlocalhost or 127.0.0.1 or cs346 server

Page 11: Php guide for beginner

http://www.shreedhoon.com/training/index.php

Exploring the Basic PHP Exploring the Basic PHP Development ProcessDevelopment Process

The basic steps you can use to develop and The basic steps you can use to develop and publish PHP pages are:publish PHP pages are:

1. Create a PHP script file and save it to a local disk1. Create a PHP script file and save it to a local disk• Test on localhost until satisfiedTest on localhost until satisfied

2. Use FTP to copy the file to the server2. Use FTP to copy the file to the server3. Access your file via URL on server using a browser3. Access your file via URL on server using a browser

• IE, Netscape, Opera, etc.IE, Netscape, Opera, etc.

Page 12: Php guide for beginner

http://www.shreedhoon.com/http://www.shreedhoon.com/training/index.phptraining/index.php

Check PHP installationCheck PHP installation Create a simple PHP script, called phpinfo.phpCreate a simple PHP script, called phpinfo.php

The PHP script starts with a <?php tag and ends The PHP script starts with a <?php tag and ends with ?>with ?>

Between these tags is a single PHP statement: Between these tags is a single PHP statement: phpinfo();phpinfo();

Copy the file to a directory of local serverCopy the file to a directory of local server For WAMP: wamp/wwwFor WAMP: wamp/www

Access the file with a browserAccess the file with a browser http://localhost/checkphp.phphttp://localhost/checkphp.php

Page 13: Php guide for beginner

http://www.shreedhoon.com/http://www.shreedhoon.com/training/index.phptraining/index.php

Page 14: Php guide for beginner

Checking the server set upChecking the server set up

Upload the phpinfo.php to cs346 serverUpload the phpinfo.php to cs346 server E.g. to huen/m00E.g. to huen/m00

Click on the linkClick on the link http://cs346.cs.uwosh.edu/huen/m00/phpinfo.php Check the various environments:Check the various environments:

ApacheApache MySQLMySQL PHP functionsPHP functions variables variables

http://www.shreedhoon.com/training/index.php

Page 15: Php guide for beginner

http://www.shreedhoon.com/http://www.shreedhoon.com/training/index.phptraining/index.php

Page 16: Php guide for beginner

http://www.shreedhoon.com/training/index.php

Creating a PHP Script FileCreating a PHP Script File Create PHP script welcome.phpCreate PHP script welcome.php

Starts with a <?php tag and ends with ?>Starts with a <?php tag and ends with ?> Between these tags is a single PHP print Between these tags is a single PHP print

statementstatement Copy the file to C:\wamp\wwwCopy the file to C:\wamp\www Access the file with Access the file with

http://127.0.0.1/welcome.phphttp://127.0.0.1/welcome.php Demo on localhostDemo on localhost Demo on cs346 serverDemo on cs346 server

Page 17: Php guide for beginner

Similarly for other PHP scriptsSimilarly for other PHP scripts

Upload welcome.php to huen/m00Upload welcome.php to huen/m00 Click on Click on http://cs346.cs.uwosh.edu/huen/m00/welcome.php

http://www.shreedhoon.com/training/index.php

<?PHP

/* welcome.php */ print ("<h1 style=\"color: blue;\">Welcome to PHP, CS346 class!</h1>");

/* Note the combination of html tags and css */?>

Page 18: Php guide for beginner

http://www.shreedhoon.com/training/index.php

Note the effect of CSS

Page 19: Php guide for beginner

http://www.shreedhoon.com/training/index.php

Alternative PHP DelimitersAlternative PHP Delimiters You can alternatively start your PHP scripts You can alternatively start your PHP scripts

with the <script> tag as follows:with the <script> tag as follows:<script language="PHP"><script language="PHP">print ("A simple initial script");print ("A simple initial script");</script></script>

If If short_open_tagshort_open_tag enabled in its configuration enabled in its configuration file (php.ini), you can use <? and ?>.file (php.ini), you can use <? and ?>.

If asp_tags is enabled in the PHP If asp_tags is enabled in the PHP configuration file, you can use <% and %> as configuration file, you can use <% and %> as delimiters.delimiters.

Page 20: Php guide for beginner

http://www.shreedhoon.com/training/index.php

Proper SyntaxProper Syntax If you have a If you have a syntax errorsyntax error then you have then you have

written one or more PHP statements that are written one or more PHP statements that are grammatically incorrect in the PHP language.grammatically incorrect in the PHP language.

The The printprint statement syntax: statement syntax:

print ( "Your message to print" );

Enclose messagein quotation

marks

Message to Output

End in asemi-colon

Parenthesis areoptional

Page 21: Php guide for beginner

http://www.shreedhoon.com/training/index.php

If syntax is wrongIf syntax is wrong<?php<?php print ( "Welcome to PHP, CS346 class!);print ( "Welcome to PHP, CS346 class!);?>?>

Page 22: Php guide for beginner

http://www.shreedhoon.com/training/index.php

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

Some PHP Syntax Issues:Some PHP Syntax Issues: Be careful to use quotation marks, parentheses, and Be careful to use quotation marks, parentheses, and

brackets in brackets in pairspairs.. 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.

Page 23: Php guide for beginner

http://www.shreedhoon.com/training/index.php

Embedding PHP Statements Within Embedding PHP Statements Within HTML DocumentsHTML Documents

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

Save the file first with extension htmlSave the file first with extension html Validate the html fileValidate the html file Change the extension to phpChange the extension to php Access the script by URL on serverAccess the script by URL on server

Page 24: Php guide for beginner

http://www.shreedhoon.com/training/index.php

<html xmlns = "http://www.w3.org/1999/xhtml"><html xmlns = "http://www.w3.org/1999/xhtml"><head><head> <title>HTML With PHP Embedded </title><title>HTML With PHP Embedded </title></head></head><body><body> <p style = "font-family:sans-serif; font-size:36; <p style = "font-family:sans-serif; font-size:36; color:yellow; background-color:green">color:yellow; background-color:green"> Welcome To My Page!Welcome To My Page! <?PHP<?PHP print ("<br /> Using PHP is not hard!");print ("<br /> Using PHP is not hard!"); ?>?> <br /> and you can learn it quickly!</p><br /> and you can learn it quickly!</p></body></body></html></html>

Page 25: Php guide for beginner

vvhttp://www.shreedhoon.com/training/index.php

When embedded1.php is accessedWhen embedded1.php is accessed

Page 26: Php guide for beginner

http://www.shreedhoon.com/training/index.php

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

Sometimes you want to output an HTML tag Sometimes you want to output an HTML tag that also requires double quotation marks.that also requires double quotation marks. Use the backslash (“\”) character to signal that the Use the backslash (“\”) character to signal that the

double quotation marks themselves should bedouble quotation marks themselves should beoutput:output:print ("<font color=\"blue\">");print ("<font color=\"blue\">");

The above statement would output:The above statement would output: <font color="blue"><font color="blue">

Page 27: Php guide for beginner

http://www.shreedhoon.com/training/index.php

Using Comments with Using Comments with PHP ScriptsPHP Scripts

Comments enable you to include Comments enable you to include descriptive text along with the PHP descriptive text along with the PHP script.script. Comment lines are ignored when the script Comment lines are ignored when the script

runs; they do not slow down the run-time.runs; they do not slow down the run-time. Comments have two common uses.Comments have two common uses.

• Describe the overall script purpose.Describe the overall script purpose.• Describe particularly tricky script lines.Describe particularly tricky script lines.

Page 28: Php guide for beginner

http://www.shreedhoon.com/training/index.php

Using Comments with PHP ScriptsUsing Comments with PHP Scripts Comment Syntax - Use // standaloneComment Syntax - Use // standalone

<?php<?php// This is a comment// This is a comment?>?>

Can be placed on Same line as a Can be placed on Same line as a statement:statement:<?php<?phpprint ("A simple initial script"); print ("A simple initial script"); //Output a line//Output a line?>?>

Page 29: Php guide for beginner

http://www.shreedhoon.com/training/index.php

Example Script with CommentsExample Script with Comments

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

Page 30: Php guide for beginner

http://www.shreedhoon.com/http://www.shreedhoon.com/training/index.phptraining/index.php

Alternative Comment SyntaxAlternative Comment Syntax

PHP allows a couple of additional ways to PHP allows a couple of additional ways to create comments.create comments.<?php<?phpphpinfo(); # This is a built-in functionphpinfo(); # This is a built-in function?>?>

Multiple line comments.Multiple line comments. <?php<?php

/*/*A script that gets information about theA script that gets information about thePHP version being used.PHP version being used.*/*/<? phpinfo(); ?><? phpinfo(); ?>

Page 31: Php guide for beginner

http://www.shreedhoon.com/http://www.shreedhoon.com/training/index.phptraining/index.php

SummarySummary

HTML pages are static and cannot interact with HTML pages are static and cannot interact with usersusers

PHP is a free, open source technology that PHP is a free, open source technology that enables documents to generate dynamic contentenables documents to generate dynamic content

PHP script has the extension of .phpPHP script has the extension of .php PHP script may be standalone orPHP script may be standalone or Can be embedded in an HTML documentCan be embedded in an HTML document

Page 32: Php guide for beginner

http://www.shreedhoon.com/http://www.shreedhoon.com/training/index.phptraining/index.php

SummarySummary

Resources needed for development:Resources needed for development: Web server with built-in PHPWeb server with built-in PHP a client machine with a basic text editor, a client machine with a basic text editor,

browser, and internet connectionsbrowser, and internet connections FTP or Telnet software to send the script to FTP or Telnet software to send the script to

the serverthe server

Page 33: Php guide for beginner

http://www.shreedhoon.com/http://www.shreedhoon.com/training/index.phptraining/index.php

SummarySummary

PHP script process: PHP script process: write the PHP script filewrite the PHP script file copy the script file to the Web servercopy the script file to the Web server access the file with a Web browser access the file with a Web browser

Comments can be proceeded with Comments can be proceeded with two forward slashes (//) two forward slashes (//) or # or # or enclosed in /* and */or enclosed in /* and */

Page 34: Php guide for beginner

Contact usContact us Website:Website: www.shreedhoon.comwww.shreedhoon.com www.shreedhoon.com/training/index.phpwww.shreedhoon.com/training/index.php Blogs:Blogs: http://Dotnettrainingingandhinagar.blogspot.inhttp://Dotnettrainingingandhinagar.blogspot.in http://dotnettrainingingandhinagar.tumblr.com/http://dotnettrainingingandhinagar.tumblr.com/ http://shreedhoontraining.weebly.com/http://shreedhoontraining.weebly.com/

http://www.shreedhoon.com/http://www.shreedhoon.com/training/index.phptraining/index.php

Page 35: Php guide for beginner

http://www.shreedhoon.com/http://www.shreedhoon.com/training/index.phptraining/index.php