php • PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. • Example:
What You Should Already Know • Before you continue you should have a basic understanding of the following: • HTML • CSS • JavaScript
What is PHP? • PHP is an acronym for "PHP: Hypertext Preprocessor" • PHP is a widely-used, open source scripting language • PHP scripts are executed on the server • PHP is free to download and use
PHP 5 Installation
Set Up PHP on Your Own PC • However, if your server does not support PHP, you must: • install a web server • install PHP • install a database, such as MySQL • The official PHP website (PHP.net) has installation instructions for PHP: http://php.net/manual/en/install.php
What is a PHP File? • PHP files can contain text, HTML, CSS, JavaScript, and PHP code • PHP code are executed on the server, and the result is returned to the browser as plain HTML • PHP files have extension ".php"
Basic PHP Syntax • PHP • PHP Case Sensitivity • Php comments
Output Variables • The PHP echo statement is often used to output data to the screen.
PHP Variables • A variable can have a short name (like x and y) or a more descriptive name (age, carname, total_volume). Rules for PHP variables: • A variable starts with the $ sign, followed by the name of the variable • A variable name must start with a letter or the underscore character • A variable name cannot start with a number • A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ) • Variable names are case-sensitive ($age and $AGE are two different variables)
PHP is a Loosely Typed Language * PHP automatically converts the variable to the correct data type, depending on its value. • In other languages such as C, C++, and Java, the programmer must declare the name and type of the variable before using it.
PHP Variables Scope • In PHP, variables can be declared anywhere in the script. • The scope of a variable is the part of the script where the variable can be referenced/used. • PHP has three different variable scopes: • local • global • static
PHP The static Keyword • Normally, when a function is completed/executed, all of its variables are deleted. However, sometimes we want a local variable NOT to be deleted. We need it for a further job.
PHP 5 echo and print Statements • echo and print are more or less the same. They are both used to output data to the screen. • The differences are small: echo has no return value while print has a return value of 1 so it can be used in expressions. echo can take multiple parameters (although such usage is rare) while print can take one argument. echo is marginally faster than print.
PHP String Functions • Get The Length of a String • The PHP strlen() function returns the length of a string.
PHP String Functions • Count The Number of Words in a String • The PHP str_word_count() function counts the number of words in a string:
Reverse a String • The PHP strrev() function reverses a string:
String Functions • Search For a Specific Text Within a String • The PHP strpos() function searches for a specific text within a string.
String Functions • Replace Text Within a String • The PHP str_replace() function replaces some characters with some other characters in a string. • echo str_replace("world", "Dolly", "Hello world!"); // outputs Hello Dolly!
PHP Operators • Operators are used to perform operations on variables and values. PHP divides the operators in the following groups: • Arithmetic operators • Assignment operators • Comparison operators • Increment/Decrement operators • Logical operators • String operators • Array operators
PHP Arithmetic Operators
PHP Assignment Operators
PHP Comparison Operators
PHP Logical Operators
PHP String Operators
Thanks

php basic part one

  • 1.
    php • PHP isa server scripting language, and a powerful tool for making dynamic and interactive Web pages. • Example:
  • 2.
    What You ShouldAlready Know • Before you continue you should have a basic understanding of the following: • HTML • CSS • JavaScript
  • 3.
    What is PHP? •PHP is an acronym for "PHP: Hypertext Preprocessor" • PHP is a widely-used, open source scripting language • PHP scripts are executed on the server • PHP is free to download and use
  • 4.
  • 5.
    Set Up PHPon Your Own PC • However, if your server does not support PHP, you must: • install a web server • install PHP • install a database, such as MySQL • The official PHP website (PHP.net) has installation instructions for PHP: http://php.net/manual/en/install.php
  • 6.
    What is aPHP File? • PHP files can contain text, HTML, CSS, JavaScript, and PHP code • PHP code are executed on the server, and the result is returned to the browser as plain HTML • PHP files have extension ".php"
  • 7.
    Basic PHP Syntax •PHP • PHP Case Sensitivity • Php comments
  • 8.
    Output Variables • ThePHP echo statement is often used to output data to the screen.
  • 9.
    PHP Variables • Avariable can have a short name (like x and y) or a more descriptive name (age, carname, total_volume). Rules for PHP variables: • A variable starts with the $ sign, followed by the name of the variable • A variable name must start with a letter or the underscore character • A variable name cannot start with a number • A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ) • Variable names are case-sensitive ($age and $AGE are two different variables)
  • 10.
    PHP is aLoosely Typed Language * PHP automatically converts the variable to the correct data type, depending on its value. • In other languages such as C, C++, and Java, the programmer must declare the name and type of the variable before using it.
  • 11.
    PHP Variables Scope •In PHP, variables can be declared anywhere in the script. • The scope of a variable is the part of the script where the variable can be referenced/used. • PHP has three different variable scopes: • local • global • static
  • 12.
    PHP The staticKeyword • Normally, when a function is completed/executed, all of its variables are deleted. However, sometimes we want a local variable NOT to be deleted. We need it for a further job.
  • 13.
    PHP 5 echoand print Statements • echo and print are more or less the same. They are both used to output data to the screen. • The differences are small: echo has no return value while print has a return value of 1 so it can be used in expressions. echo can take multiple parameters (although such usage is rare) while print can take one argument. echo is marginally faster than print.
  • 14.
    PHP String Functions •Get The Length of a String • The PHP strlen() function returns the length of a string.
  • 15.
    PHP String Functions •Count The Number of Words in a String • The PHP str_word_count() function counts the number of words in a string:
  • 16.
    Reverse a String •The PHP strrev() function reverses a string:
  • 17.
    String Functions • SearchFor a Specific Text Within a String • The PHP strpos() function searches for a specific text within a string.
  • 18.
    String Functions • ReplaceText Within a String • The PHP str_replace() function replaces some characters with some other characters in a string. • echo str_replace("world", "Dolly", "Hello world!"); // outputs Hello Dolly!
  • 19.
    PHP Operators • Operatorsare used to perform operations on variables and values. PHP divides the operators in the following groups: • Arithmetic operators • Assignment operators • Comparison operators • Increment/Decrement operators • Logical operators • String operators • Array operators
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.