Presentation is loading. Please wait.

Presentation is loading. Please wait.

10/5/2015CS346 PHP1 Module 1 Introduction to PHP.

Similar presentations


Presentation on theme: "10/5/2015CS346 PHP1 Module 1 Introduction to PHP."— Presentation transcript:

1 10/5/2015CS346 PHP1 Module 1 Introduction to PHP

2 PHP References  General: Download, documentation http://www.php.net/ http://www.php.net/ http://www.php.net/  Documentation: manual http://www.php.net/manual/en/ http://www.php.net/manual/en/ http://www.php.net/manual/en/ http://us2.php.net/manual/en/index.php http://us2.php.net/manual/en/index.phphttp://us2.php.net/manual/en/index.php  PHP.net tutorial http://php.net/manual/en/tutorial.php http://php.net/manual/en/tutorial.php http://php.net/manual/en/tutorial.php  W3schools tutorial http://www.w3schools.com/php/default.asp 10/5/2015CS346 PHP2

3 PHP functions  Documented PHP functions http://us2.php.net/quickref.php http://us2.php.net/quickref.php http://us2.php.net/quickref.php  You can create your own functions too 10/5/2015CS346 PHP3

4 10/5/2015CS346 PHP4 Objectives  What is PHP?  How does a PHP script work with a Web Browser and a Web Server?  What software and components you need to get started with PHP?  To create and run a simple PHP script

5 10/5/2015CS346 PHP5 What Is PHP?  PHP, PHP Hypertext Preprocessor Server-side scripting languages for creating dynamic web pages Server-side scripting languages for creating dynamic web pages

6 10/5/2015CS346 PHP6 PHP advantages Advantages of Using PHP to enhance Web pages: Easy to use Easy to use Simpler than Perl Simpler than Perl Open source Open source Multiple platform. Multiple platform.

7 10/5/2015CS346 PHP7 How PHP Pages are Accessed and Interpreted Client: Web browserWeb server 1.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

8 10/5/2015CS346 PHP8 Getting Started with PHP To develop and publish PHP scripts you need: A client machine with a basic text editor and Internet connection A client machine with a basic text editor and Internet connection Prepare a text file with.php extensionPrepare a text file with.php extension FTP or Telnet software FTP or Telnet software Upload the file.php to the serverUpload the file.php to the server A Web server with PHP built into it A Web server with PHP built into it Process the file.phpProcess the file.php

9 10/5/2015CS346 PHP9 WHH Note  This means that a browser e.g. IE or Firefox on the client computer will not recognize or render a file with extension.php  How do you check your PHP script before submission to server?

10 10/5/2015CS346 PHP10 Getting Started with PHP Set up development computer as a server Laptop contains a server and a browser environment Laptop contains a server and a browser environment Laptop is also set up as a Web server - WAMPserver Laptop is also set up as a Web server - WAMPserver Windows Apache, MySQL, PHPWindows Apache, MySQL, PHP Client machine: PC, XP, editors, browsers Client machine: PC, XP, editors, browsers Internet connection not needed Internet connection not needed Use copy and paste to transfer the scripts Use copy and paste to transfer the scripts  For class demos: localhost or 127.0.0.1 or cs346 server localhost or 127.0.0.1 or cs346 server

11 10/5/2015CS346 PHP11 Exploring the Basic PHP Development Process The basic steps you can use to develop and publish PHP pages are: 1. 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 server 3. Access your file via URL on server using a browser IE, Netscape, Opera, etc.IE, Netscape, Opera, etc.

12 10/5/2015CS346 PHP12 Check PHP installation  Create a simple PHP script, called phpinfo.php The PHP script starts with a The PHP script starts with a Between these tags is a single PHP statement: phpinfo(); Between these tags is a single PHP statement: phpinfo();  Copy the file to a directory of local server For WAMP: wamp/www For WAMP: wamp/www  Access the file with a browser  http://localhost/checkphp.php

13 10/5/2015CS346 PHP13

14 Checking the server set up  Upload the phpinfo.php to cs346 server E.g. to huen/m00 E.g. to huen/m00  Click on the link  http://cs346.cs.uwosh.edu/huen/m00/phpinfo.php http://cs346.cs.uwosh.edu/huen/m00/phpinfo.php  Check the various environments: Apache Apache MySQL MySQL PHP functions PHP functions variables variables 10/5/2015CS346 PHP14

15 10/5/2015CS346 PHP15

16 10/5/2015CS346 PHP16 Creating a PHP Script File  Create PHP script welcome.php Starts with a Starts with a Between these tags is a single PHP print statement Between these tags is a single PHP print statement  Copy the file to C:\wamp\www  Access the file with http://127.0.0.1/welcome.php  Demo on localhost  Demo on cs346 server

17 Similarly for other PHP scripts  Upload welcome.php to huen/m00  Click on  http://cs346.cs.uwosh.edu/huen/m00/welcome.php http://cs346.cs.uwosh.edu/huen/m00/welcome.php 10/5/2015CS346 PHP17 <?PHP /* welcome.php */ print (" Welcome to PHP, CS346 class! "); /* Note the combination of html tags and css */ ?>

18 10/5/2015CS346 PHP18 Note the effect of CSS

19 10/5/2015CS346 PHP19 Alternative PHP Delimiters  You can alternatively start your PHP scripts with the tag as follows: print ("A simple initial script"); </script>  If short_open_tag enabled in its configuration file (php.ini), you can use.  If asp_tags is enabled in the PHP configuration file, you can use as delimiters.

20 10/5/2015CS346 PHP20 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:

21 10/5/2015CS346 PHP21 If syntax is wrong <?php print ( "Welcome to PHP, CS346 class!); print ( "Welcome to PHP, CS346 class!);?>

22 10/5/2015CS346 PHP22 A Little About PHP's Syntax  Some PHP Syntax Issues: Be careful to use quotation marks, parentheses, and brackets in pairs. Be careful to use quotation marks, parentheses, 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.

23 10/5/2015CS346 PHP23 Embedding PHP Statements Within HTML Documents  One way to use PHP is to embed PHP scripts within HTML tags in an HTML document.  Save the file first with extension html  Validate the html file  Change the extension to php  Access the script by URL on server

24 10/5/2015CS346 PHP24 <head> HTML With PHP Embedded HTML With PHP Embedded </head><body> Welcome To My Page! Welcome To My Page! <?PHP <?PHP print (" Using PHP is not hard!"); print (" Using PHP is not hard!"); ?> ?> and you can learn it quickly! and you can learn it quickly! </body></html>

25 10/5/2015CS346 PHP25 When embedded1.php is accessed

26 10/5/2015CS346 PHP26 Using Backslash (\) to Generate HTML Tags with print()  Sometimes you want to output an HTML tag that also requires double quotation marks. Use the backslash (“\”) character to signal that the double quotation marks themselves should be output: print (" "); Use the backslash (“\”) character to signal that the double quotation marks themselves should be output: print (" "); The above statement would output: The above statement would output:

27 10/5/2015CS346 PHP27 Using Comments with PHP Scripts  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 run-time. Comment lines are ignored when the script 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.

28 10/5/2015CS346 PHP28 Using Comments with PHP Scripts  Comment Syntax - Use // standalone <?php // This is a comment ?>  Can be placed on Same line as a statement: <?php print ("A simple initial script"); //Output a line ?>

29 10/5/2015CS346 PHP29 Example Script with Comments 1. 1. 2. Generating HTML From PHP 2. Generating HTML From PHP 3. Generating HTML From PHP 3. Generating HTML From PHP 4. <?php 5. // 6. // Example script to output HTML tags 7. // 8. print ("Using PHP has some advantages: "); 9. print (" Speed Ease of use 9. print (" Speed Ease of use Functionality "); //Output bullet list Functionality "); //Output bullet list 10. print (" "); 11. ?>

30 10/5/2015CS346 PHP30 Alternative Comment Syntax PHP allows a couple of additional ways to create comments. <?php phpinfo(); # This is a built-in function ?>  Multiple line comments. <?php <?php/* A script that gets information about the PHP version being used. */

31 10/5/2015CS346 PHP31 Summary  HTML pages are static and cannot interact with users  PHP is a free, open source technology that enables documents to generate dynamic content  PHP script has the extension of.php  PHP script may be standalone or  Can be embedded in an HTML document

32 10/5/2015CS346 PHP32 Summary  Resources needed for development: Web server with built-in PHP Web server with built-in PHP a client machine with a basic text editor, browser, and internet connections a client machine with a basic text editor, browser, and internet connections FTP or Telnet software to send the script to the server FTP or Telnet software to send the script to the server

33 10/5/2015CS346 PHP33 Summary  PHP script process: write the PHP script file write the PHP script file copy the script file to the Web server copy 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 two forward slashes (//) two forward slashes (//) or # or # or enclosed in /* and */ or enclosed in /* and */


Download ppt "10/5/2015CS346 PHP1 Module 1 Introduction to PHP."

Similar presentations


Ads by Google