PHP TUTORIAL
18 Pages
English
Downloading requires you to have access to the YouScribe library
Learn all about the services we offer

PHP TUTORIAL

-

Downloading requires you to have access to the YouScribe library
Learn all about the services we offer
18 Pages
English

Description

PHP TUTORIAL : Table of Contents Introduction to PHP What PHP is, what a PHP file is, how PHP works, and what PHP can do for you. PHP Installation What you need to get PHP up and running! PHP Syntax Basic PHP syntax. PHP Operators The different operators used in PHP. PHP Conditional Statements Explanation of the if...else... statement and the switch statement. PHP Looping Explanation of the while statement, the do while statement, and the for statement. PHP Functions Some useful PHP functions. PHP More Functions Some other useful PHP functions. PHP Forms How PHP deals with HTML forms. PHP Cookies How to set and retrieve cookies in PHP. PHP Including Files (SSI) How to include files in PHP. PHP Date() How to work with Date formats in PHP. PHP ODBC How to connect to a database. 1- INTRODUCTION A PHP file may contain text, HTML tags and scripts. Scripts in a PHP file are executed on the server. What you should already know Before you continue you should have some basic understanding of the following: WWW, HTML and the basics of building Web pages Some scripting knowledge If you want to study these subjects, go to our Home Page What is PHP? • PHP stands for PHP: Hypertext Preprocessor • PHP is a server-side scripting language, like ASP • PHP scripts are executed on the server • PHP supports many databases (MySQL, Informix, Oracle, Sybase, Solid, PostgreSQL, Generic ODBC, etc.) • PHP is an open source ...

Subjects

Informations

Published by
Reads 77
Language English

Exrait

PHP TUTORIAL :                                                       ! "  #    "    "  $  #    "    "    "  %  "     & %  "      %"      &$ "  !      '      % ()         *()      * "    *!       +     1- INTRODUCTION                      
!    "#      ' " +    ,
 
  &$   +  + +   "         +-    "   
!  $ ·     ,    ·     '.    / ·        ' ·    " + (&0$ "  +  0$ 1 *! ) ·        () ·         !    %$ ·    "   &$    ·        +   &$ ·    '     22 232  2"2 !  &$ ·  &0$   " + ' ·  &0$    "  ""  ·  &0$   0$ ·  &0$ "   "+  " ·  &0$        ' & ·   "+  &0$  ." ("    '    '   4 ") ! $  ·     " ( $ 4 ) ·    "+  "  '   (/  ) ·    %5##   "    ,   ·            '  !  $ ·    / '     $ " ·        $ " ·   &0$     $ "   2- INSTALLATION   
 
What do You Need?           &0$  / '   '   .  6     7     "       . -  "     +  .   '   "   & +     '   '      "           " +"     8, ,99"9+"9::98898";<"" Download PHP *    , ,999 Download MySQL Database * &0$   , ,99"="99" Download Apache Server * /   , ,999"99    3- PHP SYNTAX   (  #       )*# )   # +  #         #                   "   #
,   /   "  &$  -   &$   "      '  "   "       2 2   +, <html> <body> <?php echo "Hello World"; ?> </body> </html> /   +    -$   $.  /   +  +     " #     "    "  "             " 
 
   + "     ,       " +'  '    "     2 2
*   / '+      >  "+ ?+ "   "+          2 2   '+  >,
<html> <body> <?php $txt="Hello World"; echo $txt; ?> </body> </html>     " '+     () ,
<html> <body> <?php $txt1="Hello World"; $txt2="1234"; echo $txt1 . " " . $txt2 ; ?> </body> </html>      +'  +, 2  @A382
       99  "  . ""  9B  B9  "   "" +
<html> <body> <?php //This is a comment /* This is a comment block */ ?> </body> </html>    4- PHP OPERATORS  /      
 
 
 /           /  /  0  C / . + B &   9 *' E & (' ") CC " .. *"  /  /  1  < <   C< C< .< .<   B< B<  <  < E< E<  /  /  0  <<     <     H        I H<        I<         /  /  0  JJ  KK 
1  <A CA <A D. <8 BD @D D D9A DEA @:EF @:EA <D CC  <D ..
3     < <C < . <B < <E
1  D<<F   D<F   DHF   DIF   DH<F   DI<F  
2 8 3 A: 3 AD @ A : <G <8
1  <G <3  I @: JJ H @   <G <3 <<D <<D  
 
 
<G <3  <<  
   5- CONDITIONNALS                  
  ?         "      7    "          '   ", ·   45  .   "               (       ) ·  #  .   "        "       
 3       "                  " Syntax if ( condition ) code to be executed if condition is true;  else code to be executed if condition is false;  Example    "   2'   2      %     2'   2, <html> <body> <?php $d=date("D"); if ($d=="Fri") echo "Have a nice weekend!"; else echo "Have a nice day!"; ?> </body> </html> 
 
 
 "     +          +    +, <html> <body> <?php $x=10; if ($x==10) { echo "Hello<br />"; echo "Good morning<br />"; } ?> </body> </html>   #         " +    +     " Syntax switch ( expression ) { case label1:    code to be executed if expression = label1;   break; case label2:    code to be executed if expression = label2;   break; default:   code to be executed  if expression is different  from both label1 and label2;  } Example      , %  '    ("   '+)   '   '      "   '           "  +         4 "  '   "      "   "          <html> <body> <?php switch ($x) { case 1:  echo "Number 1";  break; case 2:  echo "Number 2";  break; case 3:  echo "Number 3";  break; default:  echo "No number between 1 and 3"; } ?>
 
</body> </html>   6- INSTRUCTIONS DE BOUCLE             "        
 
 ?         " +      "+  " 7    "     "     '    ", ·  # .    +           ·  #.    +                 ·   .    +     "+  " ·   .    +     "     
 #    "    +           Syntax while ( condition ) code to be executed ; Example    " "            '+      =  D    + @  "   , <html> <body> <?php  $i=1; while($i<=5) { echo "The number is " . $i . "<br />"; $i++; } ?> </body> </html>   # 
 
 
  "    +      .              Syntax do { code to be executed; } while ( condition ); Example    "  "  '          "  '+      '    D, <html> <body> <?php  $i=0; do { $i++; echo "The number is " . $i . "<br />"; } while ($i<5); ?> </body> </html>       "       " "      "     " Syntax for ( initialization ; condition ; increment ) {     code to be executed;  } 67   "   "   "   L '+   "       "   " =  ""    "   '+      L   "     +  + ""   " '     Example   "    2 2 ' ", <html> <body> <?php for ($i=1; $i<=5; $i++) { echo "Hello World!<br />"; } ?> </body> 
</html>     $ '   ' +  "     '    "    >'      ' +  .      6 +     "  Syntax foreach ( array as value ) {     code to be executed;  } Example    " "       '   ' , <html> <body> <?php $arr=array("one", "two", "three"); foreach ($arr as $value) { echo "Value: " . $value . "<br />"; } ?> </body> </html>   7- FONCTIONS    #       3  +     899  
 %            / "      
 3  ()       "      +  '  '        The phpinfo() function options 6 
0 
 
 
 
       +  + '  "  "  8  $  " '   ' $ " #'" '+ " /  '+ " #1! #'" 1#  ! '   "     +'     '
 
M% 1#M#5/$ N N M% !5#* M% !M%145/M M% &*4$# N N M% #M?5M&#M M% ?/5/$# N N M% $!#M# N M% /$$ Example  <html> <body> <?php // Show all PHP information phpinfo(); ?> <?php // Show only the general information _ phpinfo(INFO GENERAL); ?> </body> </html>    * / '  "    45$   " " 6  6 +   "  "    '+    >N#5?#5   ' '+    ' "  > #5?#5   N + '+ .  "  6 '+        Example   "    45$   " "  6 +   6  , <html> <body> <?php echo "Referer: " . $ SERVER["HTTP REFERER"] . "<br />"; _ _ echo "Browser: " . $ SERVER["HTTP USER AGENT"] . "<br />"; _ _ _ _ _ echo "User's IP address: " . $ SERVER["REMOTE ADDR"]; ?> </body> </html>   45 %  ()         '    67   " +  +      