1 / 27

Introduction to PHP

Discover the simplicity, efficiency, and security of PHP, a server-side scripting language that is widely used for websites. Learn about its syntax, popularity, and characteristics, and get started with your first PHP script.

kli
Download Presentation

Introduction to PHP

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. Introduction to PHP

  2. PHP? • PHP started out as a small open source project that evolved as more and more people found out how useful it was. RasmusLerdorf unleashed the first version of PHP way back in 1994. • PHP: Hypertext Preprocessor • PHP Syntax is C-Like • Server side scripting language that is embedded in HTML • PHP supports a large number of major protocols

  3. Characteristics of PHP • Simplicity • Efficiency • Security • Flexibility • Familiarity

  4. Popularity of PHP • The PYPL PopularitY of Programming Language Index is created by analyzing how often language tutorials are searched on Google.

  5. PHP Market Share

  6. Usage of Server-side programming languages for websites

  7. Escaping in PHP • Canonical PHP tags: • <?php...?> • Short-open (SGML-style) tags: • <?...?> • Set the short_open_tag setting in your php.ini file to on. This option must be disabled to parse XML with PHP because the same syntax is used for XML tags. • ASP-style tags • <%...%> • HTML script tags: • <script language="PHP">...</script>

  8. Exercise • Create your first PHP script. Write the string “Hello world..is it me you’re looking for?”

  9. Commenting PHP code • Single-line comments • #This is a comment • //This is a comment • Multi-lines comments • /* This is a comment for multiple lines */

  10. Things to Remember • PHP is whitespace insensitive • PHP is case sensitive • Statements are expressions terminated by semicolons • Expressions are combinations of tokens • Braces make blocks

  11. Variables • All variables in PHP are denoted with a leading dollar sign ($). • The value of a variable is the value of its most recent assignment. • Variables are assigned with the = operator, with the variable on the left-hand side and the expression to be evaluated on the right. • Variables can, but do not need, to be declared before assignment. • Variables in PHP do not have intrinsic types - a variable does not know in advance whether it will be used to store a number or a string of characters. • Variables used before they are assigned have default values. • PHP does a good job of automatically converting types from one to another when necessary. • PHP variables are Perl-like.

  12. PHP Data Types • Integer • Doubles • Booleans • NULL • String • Array • Object • Resources Simple Types Compound Types Special variables that reference to external resources

  13. Variable Scopes • Local variables – variable declared in a function, and can only be referenced in that function.

  14. Variable Scopes • Function parameters - are declared after the function name and inside parentheses.

  15. Variable Scopes • Global variables – can be accessed in any part of the program. Must be declared using the keyword GLOBAL

  16. Variable Scopes • Static variables – does not lose the value when the function exits and will still hold the value when it is called again. Uses the keyword STATIC

  17. Variable naming • Variable names must begin with a letter or underscore character. • A variable name can consist of numbers, letters, underscores but you cannot use characters like + , - , % , ( , ) . & , etc • There is no size limit for variables.

  18. Operator types • Arithmetic Operators

  19. Operator types • Comparison Operators

  20. Operator types • Logical Operators

  21. Operator types • Assignment Operators

  22. Operator types • Conditional Operators

  23. Precedence of PHP Operators

  24. If…else statement

  25. ElseIf statement

  26. Switch statement

  27. Exercise • Create a variable named count and assign the number 0 • Create a

More Related