1 / 14

PHP: An Introduction to Dynamic Web Development

Learn the basics of PHP scripting language, how to write PHP scripts, use variables and operators, and create dynamic web content.

jwilmoth
Télécharger la présentation

PHP: An Introduction to Dynamic Web Development

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. PHP: An Introduction

  2. PHP • PHP is a scripting language used for server side processing on Web servers. • PHP combines ease of use with sophisticated capability. • PHP lets you provide dynamic Web content, that is content that can automatically change from day to day or even minute to minute. • PHP is able to access files, databases, and other resources on the Web servers.

  3. PHP • PHP scripts can be written using Notepad or any other text editors. • You can also use special HTML editors such as Dreamweaver MX which provide syntax coloring and other features that aid PHP programmers.

  4. PHP • echo statement: • A PHP statement that sends output to a Web browser so a user can view it. • echo(“put some text here”); • HTML statements can be included in echo statements: • Echo(“<H2>A Likely Story</H2>”); • Note: All PHP statements end with a semicolon.

  5. PHP • PHP statements are enclosed in <? … ?> <? // example-script.php // This script prints a message the user can read. echo(“This is a very simple script”); <? • The statements with the “//” are comments. Comments can also be enclosed like the following: /* this is a multi-line comment. It can consist of as many lines as you like. */

  6. PHP • Variables in PHP: • Start with a dollar sign ($) • Follow the dollar sign with a letter or underscore ( _ ). The letter can be uppercase or lowercase. • Continue by adding as many letters, digits, or underscores as you like. • Variables in PHP are case sensitive Examples: $winner, $Winner, $highest_score, $x

  7. PHP Operators + Addition • Subtraction * Multiplication / Division % Modulus ++ Increment -- Decrement . Concatenation

  8. Conditional Operators a<b true if a is less than b a>b true if a is greater than b a<=b true if a is equal to or less than b a>=b true if a is equal to or greater than b a==b true if a is equal to b in value a!=b true if a not equal to b a===b true is identical (same type & value) a!==b true is not identical

  9. Conditional Operators • x AND y true if both x and y are true • x && y true if both x and y are true • x OR y true if either or both are true • x || y true if either of both are true • x XOR y true if exactly one is true • !x true is x is false

  10. Accessing PHP Pages • PHP pages must be executed on your Web Server. • On the Auburn Server, if your webpage is named “firstprogram.php” and you placed it in the root directory of your Web Site at www.auburn.edu/~smithjr, you would access the php page with: http://www.auburn.edu/~smithjr/firstprogram.php

  11. A Simple PHP Program: <html> <head> <title> Generating HTML from PHP </title> </head> <? print ("Using PHP has <i>some advantages:</i>"); echo ("<ul> <li>Speed</li> <li>Ease of use</li> <li>Functionality</li> </ul>"); print ("</body> </html>"); ?>

  12. String Variables • Manipulating string variables is an important task in any programming language. • The Concatenate Operator in PHP is the “.” (dot) sign. • $firstname.$lastname would concatenate the content of the variable “$firstname” with the content of the variable “lastname.”

  13. String Functions • The strlen() function: Returns the number of characters in the string variable, e.g., $len = strlen($firstname); would return the number of characters in the variable $firstname. • The trim() function: Removes any blank characters from the beginning and end of a string, e.g., $name= trim($name);

  14. String Functions • The strtolower() and strtoupper() functions: Return the input string in all lowercase or all uppercase, respectively. • The substr() function: Extract a portionof the characters in a string variable, e.g., $part=substr($name, 0, 5); returns five characters starting at position 0, that is, characters 0 through 4.

More Related