Internet Technologies PHP PHP is a server scripting

  • Slides: 20
Download presentation
Internet Technologies PHP

Internet Technologies PHP

 • PHP is a server scripting language, and a powerful tool for making

• PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. • 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

What is a PHP File? PHP files can contain text, HTML, CSS, Java. Script,

What is a PHP File? PHP files can contain text, HTML, CSS, Java. Script, and PHP code are executed on the server, and the result is returned to (1) the browser as Lec plain HTML PHP files have extension ". php" : ﻗﺎﻝ ﺭﺳﻮﻝ ﺍﻟﻠﻪ ﺻﻠﻲ ﺍﻟﻠﻪ ﻋﻠﻴﻪ ﻭﺳﻠﻢ ” " ﺍ ﻱ ﺍ ﺍ ﺍﻟ ﻭﺍ ﺍ ﺍ . ﻱ ﻳﺍ , ﺍ

What Can PHP Do? PHP can generate dynamic page content PHP can create, open,

What Can PHP Do? PHP can generate dynamic page content PHP can create, open, read, write, delete, and close files the server Lecon(1) PHP can collect form data PHP can send and receive cookies PHP can add, delete, modify data in : ﻗﺎﻝ ﺭﺳﻮﻝ ﺍﻟﻠﻪ ﺻﻠﻲ ﺍﻟﻠﻪ ﻋﻠﻴﻪ ﻭﺳﻠﻢ your database ” " ﺍ ﻱ ﺍ ﺍ ﺍﻟ ﻭﺍ ﺍ ﺍ PHP can be used to control user-access. ﻱ ﻳﺍ , ﺍ PHP can encrypt data

Why PHP? PHP runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.

Why PHP? PHP runs on various platforms (Windows, Linux, Unix, Mac OS X, etc. ) PHP is compatible with almost all servers Lec (1) used today (Apache, IIS, etc. ) PHP supports a wide range of databases PHP is free. Download it from the official : ﻗﺎﻝ ﺭﺳﻮﻝ ﺍﻟﻠﻪ ﺻﻠﻲ ﺍﻟﻠﻪ ﻋﻠﻴﻪ ﻭﺳﻠﻢ PHP resource: www. php. net ” " ﺍ ﻱ ﺍ ﺍ ﺍﻟ ﻭﺍ ﺍ ﺍ PHP is easy to. learn ﻱ ﻳﺍ , ﺍ ﺍ and , ﺍ runs efficiently on the server side

Basic PHP Syntax A PHP script can be placed anywhere in the document. A

Basic PHP Syntax A PHP script can be placed anywhere in the document. A PHP script starts with Lec (1) <? php and ends with ? > : ﻗﺎﻝ ﺭﺳﻮﻝ ﺍﻟﻠﻪ ﺻﻠﻲ ﺍﻟﻠﻪ ﻋﻠﻴﻪ ﻭﺳﻠﻢ ” " ﺍ ﻱ ﺍ ﺍ ﺍﻟ ﻭﺍ ﺍ ﺍ . ﻱ ﻳﺍ , ﺍ

Example : <? php // This is a single-line comment # This is also

Example : <? php // This is a single-line comment # This is also a single-line comment Lec (1) echo "Hello World!"; /* This is a multiple-lines : ﻗﺎﻝ ﺭﺳﻮﻝ ﺍﻟﻠﻪ ﺻﻠﻲ ﺍﻟﻠﻪ ﻋﻠﻴﻪ ﻭﺳﻠﻢ comment lines ” " ﺍ ﻱ ﺍ ﺍ ﺍﻟ ﻭﺍ ﺍ ﺍ . ﻱ ﻳﺍ , ﺍ */ ? >

PHP echo and print Statements In PHP there are two basic ways to get

PHP echo and print Statements In PHP there are two basic ways to get output: echo and print. The differences are small: echo has no return Lecvalue (1) while print has a return value of 1 so it can be used in expressions. echo can take multiple parameters : ﻗﺎﻝ ﺭﺳﻮﻝ ﺍﻟﻠﻪ ﺻﻠﻲ ﺍﻟﻠﻪ ﻋﻠﻴﻪ ﻭﺳﻠﻢ while print can take one argument. ” " ﺍ ﻱ ﺍ ﺍ ﺍﻟ ﻭﺍ ﺍ ﺍ . ﻱ ﻳﺍ , ﺍ faster ﺍ , ﺍ than print. echo is marginally

Example : <? php echo "Hello world! "; echo "This ", "string ", "was

Example : <? php echo "Hello world! "; echo "This ", "string ", "was ", "made ", "with multiple parameters. "; Lec (1) print "<h 2>PHP is Fun!</h 2>"; ? > Creating (Declaring) PHP Variables ﺗﻌﺮﻳﻒ ﻣﺘﻐﻴﺮ Variables are "containers" for storing information. ﻭﺳﻠﻢ $ ﻋﻠﻴﻪ ﺍﻟﻠﻪ ﺻﻠﻲ by ﺭﺳﻮﻝ In PHP, a variable starts with: the sign, ﺍﻟﻠﻪ followed the ﻗﺎﻝ ” " ﺍ ﻱ ﺍ ﺍ ﺍﻟ ﻭﺍ ﺍ ﺍ name of the variable: . ﻱ ﻳﺍ , ﺍ

Rules for PHP variables: • A variable starts with the $ sign, followed by

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 Lec (1) the underscore character • A variable name cannot start with a number • A variable name can only contain alphanumeric characters and underscores (A-z, 0 -9, : ﻗﺎﻝ ﺭﺳﻮﻝ ﺍﻟﻠﻪ ﺻﻠﻲ ﺍﻟﻠﻪ ﻋﻠﻴﻪ ﻭﺳﻠﻢ and _ ) ” " ﺍ ﻱ ﺍ ﺍ ﺍﻟ ﻭﺍ ﺍ ﺍ • Variable names. are ($age and ﻱ ﻳﺍ , case-sensitive ﺍ ﺍ , ﺍ $AGE are two different variables)

GLOBAL SCOPE : A variable declared outside a function has a GLOBAL SCOPE and

GLOBAL SCOPE : A variable declared outside a function has a GLOBAL SCOPE and can only be accessed outside a function <? php $x = 5; // global scope function my. Test() { } my. Test(); echo $x; ? > Lec (1) : ﻗﺎﻝ ﺭﺳﻮﻝ ﺍﻟﻠﻪ ﺻﻠﻲ ﺍﻟﻠﻪ ﻋﻠﻴﻪ ﻭﺳﻠﻢ ” " ﺍ ﻱ ﺍ ﺍ ﺍﻟ ﻭﺍ ﺍ ﺍ . ﻱ ﻳﺍ , ﺍ

LOCAL SCOPE : A variable declared within a function has a LOCAL SCOPE and

LOCAL SCOPE : A variable declared within a function has a LOCAL SCOPE and can only be accessed within that function <? php Lec (1) function my. Test() { $x = 5; // local scope echo $x; } : ﻗﺎﻝ ﺭﺳﻮﻝ ﺍﻟﻠﻪ ﺻﻠﻲ ﺍﻟﻠﻪ ﻋﻠﻴﻪ ﻭﺳﻠﻢ ” " ﺍ ﻱ ﺍ ﺍ ﺍﻟ ﻭﺍ ﺍ ﺍ my. Test(); . ﻱ ﻳﺍ , ﺍ ? >

PHP The global Keyword The global keyword is used to access a global variable

PHP The global Keyword The global keyword is used to access a global variable from within a function. <? php $x = 5; $y = 10; function my. Test() { global $x, $y; $y = $x + $y; } my. Test(); // run function echo $y; // output the new value for variable $y ? > PHP also stores all global variables in an array called $GLOBALS[index]. <? php $x = 5; $y = 10; function my. Test() { : ﺍﻟﻠﻪ ﺻﻠﻲ ﺍﻟﻠﻪ ﻋﻠﻴﻪ ﻭﺳﻠﻢ $GLOBALS['y'] = $GLOBALS['x'] + $GLOBALS['y']; } ” ﺍ ﺍﻟ ﻭﺍ ﺍ ﺍ Lec (1) my. Test(); echo $y; // outputs 15 ? > . ﻱ ﻳﺍ , ﺍ ﻗﺎﻝ ﺭﺳﻮﻝ " ﺍﻱ ﺍ

PHP The static Keyword Normally, when a function is completed/executed, all of its variables

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 function my. Test() { static $x = 0; Lec (1) echo $x; $x++; } my. Test(); echo " "; : ﻗﺎﻝ ﺭﺳﻮﻝ ﺍﻟﻠﻪ ﺻﻠﻲ ﺍﻟﻠﻪ ﻋﻠﻴﻪ ﻭﺳﻠﻢ my. Test(); ” " ﺍ ﻱ ﺍ ﺍ ﺍﻟ ﻭﺍ ﺍ ﺍ echo " "; . ﻱ ﻳﺍ , ﺍ my. Test(); ? >