SlideShare a Scribd company logo
1 of 146
02/21/12 Open Source Programming
02/21/12 Open Source Programming Introduction  Unit – I  Open source Programming PHP, Apache, MySQL, Postgress, SQL and Perl- Overview of PHP – Variables, operators, Constants, control structures arrays, Functions, classes – Handling files.
02/21/12 By allowing the open exchange of information, programmers from all over the world contribute to make a truly powerful and efficient piece of software without royalties or fees. Open Source Programming What is Open source
02/21/12 ,[object Object],[object Object],[object Object],Open Source Programming Why OSP ROCKS?
02/21/12 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Open Source Programming OSP Software - OS
02/21/12 Apache  — HTTP web server  Tomcat web server  — web container  Mediawiki  — wiki server software  Alfresco, TYPO3  — content management system  RenovatioCMS  — content management system  Joomla  — content management system  Drupal  — content management system provides a collaborative environment for social networking sites, corporate Web sites, intranets, e-commerce applications and discussion sites. Open Source Programming OSP Software - Server
02/21/12 WordPress  — blog software  MongoDB  — document-oriented, non-relational  database  Moodle  — course management system or virtual learning environment  openSIS  — open source Student Information System Open Source Programming OSP Software
02/21/12 osCommerce  —  allows store owners to setup, run, and maintain online stores with minimum effort and with no costs P eaZip  — File archiver  Mozilla Firefox  — web browser  OpenOffice.org  — office suite  Stockfish  — chess engine series, one of the strongest chess programs  7-Zip  – File Archiver Open Source Programming OSP Software
02/21/12 PHP   —  Hypertext Preprocessor   Ruby,Tcl/Tk PERL & Python  — Interpreted Dynamic Language MySQL   —  Data Base Open Source Programming OSP Software (Others)
open source companies ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],02/21/12
02/21/12 ,[object Object],[object Object],[object Object],[object Object]
02/21/12
02/21/12 ,[object Object],Open Source Programming ,[object Object],[object Object],[object Object],Intro to AMP Package
02/21/12 Open Source Programming AMP as Restaurant ,[object Object]
02/21/12 Open Source Programming AMP as Restaurant ,[object Object]
02/21/12 Open Source Programming AMP as Restaurant MySQL –  This is  Stockroom  of ingredients.
LICENSES  ,[object Object],[object Object],[object Object],[object Object],02/21/12
02/21/12 GNU General Public License (GPL) GNU Library or "Lesser" General Public License (LGPL) MIT license (MIT) Mozilla Public License 2.0 (MPL-2.0) Common Development and Distribution License (CDDL-1.0) Eclipse Public License (EPL-1.0)
02/21/12 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Open Source Programming Apache Introduction
02/21/12 ,[object Object],[object Object],[object Object],[object Object],[object Object],Open Source Programming HTTP request types
02/21/12 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Open Source Programming System Architecture
02/21/12 Open Source Programming ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Overview of  Php
02/21/12 ,[object Object],[object Object],ASP, SSJS, JSP….. ,[object Object],[object Object],[object Object],Open Source Programming Features of  PHP
02/21/12 Open Source Programming CLIENT WEB SERVER HTTP Request (url) <HTML> <?php PHP code ?> </HTML> Gets Page <HTML> <B>Hello</B> </HTML> Interprets the PHP code Server response How it works? Browser creates the web page
02/21/12 Open Source Programming ,[object Object],[object Object],PHP with HTML
02/21/12 Open Source Programming ,[object Object],[object Object],[object Object],[object Object],PHP with HTML
02/21/12 Open Source Programming PHP is denoted in the page with opening and closing tags as follows: <?php //php code ; ?> PHP Syntax
02/21/12 <HTML> <HEAD> <TITLE> My First PHP Program </TITLE> <h1> </HEAD> <BODY> <?php echo “I’m a PHP Program.”; ?> </BODY> </HTML> Open Source Programming Code PHP Programs Result
02/21/12 <?php $name=“VIT UNIVERSITY”; echo ‘My name is ‘,$name; ?> Open Source Programming Code PHP Programs Result
02/21/12 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Open Source Programming Data Type
02/21/12 ,[object Object],[object Object],[object Object],[object Object],[object Object],Open Source Programming Constants
02/21/12 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Open Source Programming Variables
02/21/12 Open Source Programming ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Variables
02/21/12 Open Source Programming Variables ,[object Object],[object Object],[object Object],[object Object]
02/21/12 $MyStrVal = &quot; This is an example of a string value &quot;; $MyIntVal = 145665; // An  integer value $MyBoolval = True; // A  Boolean value  can either be  True or False  $MyFloatVal=2346.45 // A  float value $MyArrVal[0] = &quot;My&quot;; //A  array  containing three  elements  $MyArrVal[1] = &quot;First&quot;;  $MyArrVal[2] = &quot;Array&quot;;  Open Source Programming Variables (cont)
02/21/12 Open Source Programming In PHP, Variable type can be changed by  Settype Syntax: Settype(Variablename, “newDataType”); E.g. $pi = 3.14 //float Settype($pi,”string”); //now string –  “3.14” Settype($pi,”integer”);// now integer -  3 Settype Settype
02/21/12 Open Source Programming Syntax: Gettype(Variablename);  E.g. $pi = 3.14; //float print gettype($pi); Print “---$pi <br>”;  Settype($pi,”string”);  print gettype($pi); Print “---$pi <br>”;  Settype($pi,”integer”); print gettype($pi); Print “---$pi <br>”;  In PHP, Variable type and can know by  Gettype . Settype & Gettype
02/21/12 ,[object Object],[object Object],[object Object],[object Object],Open Source Programming Operators
02/21/12 Open Source Programming ,[object Object],[object Object],$name = &quot;Phil&quot;; $age  = 23; echo '$name is $age'; $name = &quot;Phil&quot;; $age  = 23; echo “$name is $age”; Output is   $name is $age Output is   Phil is 23 Quotes ( “  Vs.  ‘ )
02/21/12 Logical  Operator Open Source Programming Operators (cont) Comparison Operator And Or ! Xor && ( high precedence) || ( high precedence) == != < > <= >= === (identical)
02/21/12 Open Source Programming ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Comment Line in PHP
02/21/12 Open Source Programming 1.  Echo  &  Print()  is the common method in outputting data. Since it is a language construct, echo doesn’t require parenthesis like print(). 2. Output Text Usage:  <?php  echo “Hello World”;  print(“Hello World”);   // prints out Hello World ?>  Output in PHP
02/21/12 Open Source Programming 3. Output the value of a PHP variable: <?php  echo $hits;  // prints out the number of hits print ($hits);  // returns a value if print process success. ?> 4. Can use  “<br>” , to print in next line: <?php  echo $a , “<br>”, $b ;  // prints a & b in separate lines   ?> Output in PHP
02/21/12 1. If…else Statement –  single decision stmt ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Syntax E.g. Open Source Programming Conditional  Statements (Branching)
02/21/12 2. If…else if Statement –  multiple decision stmt ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Syntax E.g. Open Source Programming Conditional Statements (Branching)
02/21/12 3. Switch Statement –  replacement of “if …… else if stmt”. ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Syntax E.g. Open Source Programming Conditional Statements  (Branching)
02/21/12 Open Source Programming 4. For Statement –  replacement of “if …… else if stmt”. ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Syntax E.g. Conditional Statements (Looping)
02/21/12 5. Do … While Statement  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Syntax E.g. Open Source Programming Conditional Statements (Looping)
02/21/12 5. While Statement  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Syntax E.g. Open Source Programming Conditional Statements (Looping)
02/21/12 ,[object Object],Open Source Programming ,[object Object],Arrays Let’s store a person’s name and age under one variable name : $name = array(‘firstname’=>’Albert’,‘lastname’=>’Einstein’,‘age’=>124);
02/21/12 Open Source Programming <?php $name[ ’firstname’ ] = “Albert”; $name[ ’lastname’ ] = “Einstein”; $name[ ’age’ ] = 124; ?> <?php $flavor[] = ‘blue rasberry’; $flavor[] = ‘root beer’; $flavor[] = ‘pineapple’; ?> Array with Implicit key Array with Explicit key Arrays
02/21/12 Open Source Programming Array of arrays is called as multidimensional arrays.  $Student = array ( &quot;0&quot;=> array (&quot;name&quot;=>&quot;James&quot;, &quot;sex&quot;=>&quot;Male&quot;, &quot;age&quot;=>&quot;28&quot;), &quot;1&quot;=> array (&quot;name&quot;=>&quot;John&quot;, &quot;sex&quot;=>&quot;Male&quot;, &quot;age&quot;=>&quot;25&quot;), &quot;2&quot;=> array (&quot;name&quot;=>&quot;Susan&quot;, &quot;sex&quot;=>&quot;Female&quot;, &quot;age&quot;=>&quot;24&quot;)); $student[“1&quot;][“name&quot;] – returns John Multidimensional Arrays
02/21/12 $u= array ( &quot;0&quot;=> array (&quot;name&quot;=>&quot;James&quot;, &quot;sex&quot;=>&quot;Male&quot;, &quot;age&quot;=>&quot;28&quot;), &quot;1&quot;=> array (&quot;name&quot;=>&quot;John&quot;, &quot;sex&quot;=>&quot;Male&quot;, &quot;age&quot;=>&quot;25&quot;), &quot;2&quot;=> array (&quot;name&quot;=>&quot;Susan&quot;, &quot;sex&quot;=>&quot;Female&quot;, &quot;age&quot;=>&quot;24&quot;)); foreach ($u as $key=>$value) { echo &quot;$key is $value&quot;; echo &quot;The actual user is $key.<br/>&quot;; foreach ($value as $iKey => $iValue) { echo &quot; ---> $iKey -> $iValue <br/>&quot;; } } ?>
02/21/12 Output : 0 is Array The actual user is 0. ---> name -> James  ---> sex -> Male  ---> age -> 28  1 is Array The actual user is 1. ---> name -> John  ---> sex -> Male  ---> age -> 25  2 is Array The actual user is 2. ---> name -> Susan  ---> sex -> Female  ---> age -> 24
02/21/12 <html> <body> <FORM ACTION =“arr.php&quot; METHOD = &quot;post&quot;> ur name <INPUT TYPE=&quot;text&quot; NAME=&quot;ur name&quot;><br> cost <INPUT TYPE=&quot;text&quot; NAME=&quot;cost&quot;><br> days <INPUT TYPE=&quot;text&quot; NAME=&quot;days&quot;><br> <INPUT TYPE=&quot;submit&quot;name=&quot;submit&quot;><br> <?php if(isset($_POST['submit'])) { $d[0]=$_POST['cost']; $d[1]=$_POST['days']; $d[2]=$d[0]+$d[1]; echo &quot;output <INPUT TYPE=text value=$d[2]>&quot;; foreach($d as $v) echo &quot;output <INPUT TYPE=text value=$v>&quot; } ?> </body> </form> </html>
02/21/12 Functions:   A function   is a block of code that is not immediately executed but can be called by scripts whenever needs. Functions can be  built-in  or  user-defined . They can require information to be passed to them and usually return a value. Open Source Programming Functions
02/21/12 Open Source Programming <?php $a=array(&quot;a&quot;=>&quot;Dog&quot;,&quot;b&quot;=>&quot;Cat&quot;,&quot;c&quot;=>&quot;Horse&quot;); print_r($a); ?>  Array ( [a] => Dog [b] => Cat [c] => Horse )  Array( key=>value )  – Creates an array with keys and values Output: E.g.: Array Functions
02/21/12 Open Source Programming array_chunk( array,size,preserve_key   )  -  splits an array into chunks of new arrays  Array Functions
02/21/12 Array ( [0] => Array ( [0] => Cat [1] => Dog ) [1] => Array ( [0] => Horse [1] => Cow ) )  Output: <?php $a=array(&quot;a&quot;=>&quot;Cat&quot;,&quot;b&quot;=>&quot;Dog&quot;,&quot;c&quot;=>&quot;Horse&quot;,&quot;d&quot;=>&quot;Cow&quot;); print_r(array_chunk($a,2)); ?>  E.g.: 1 Open Source Programming Array Functions
02/21/12 Array ( [0] => Array ( [a] => Cat [b] => Dog ) [1] => Array ( [c] => Horse [d] => Cow ) )  Output: <?php $a=array(&quot;a&quot;=>&quot;Cat&quot;,&quot;b&quot;=>&quot;Dog&quot;,&quot;c&quot;=>&quot;Horse&quot;,&quot;d&quot;=>&quot;Cow&quot;); print_r(array_chunk($a,2,true)); ?>  E.g.: 2 Open Source Programming Array Functions
02/21/12 array_combine( array1,array2 )  creates an array by combining two other arrays, where the first array is the keys, and the other array is the values. Open Source Programming Array Functions Array ( [a] => Cat [b] => Dog [c] => Horse [d] => Cow )  Output: <?php $a1=array(&quot;a&quot;,&quot;b&quot;,&quot;c&quot;,&quot;d&quot;); $a2=array(&quot;Cat&quot;,&quot;Dog&quot;,&quot;Horse&quot;,&quot;Cow&quot;); print_r(array_combine($a1,$a2)); ?>  E.g.:
02/21/12 array_count_values( array )   returns an array, where the keys are the original array's values, and the values is the number of occurrences. Open Source Programming <?php $a=array(&quot;Cat&quot;,&quot;Dog&quot;,&quot;Horse&quot;,&quot;Dog&quot;); print_r(array_count_values($a)); ?>  E.g:   Array ( [Cat] => 1 [Dog] => 2 [Horse] => 1 )  Output:   Array Functions
02/21/12 array_diff( arr1,arr2,… )  function compares two or more arrays, and returns an array with the keys and values from the first array, only if the value is not present in any of the other arrays.  Open Source Programming <?php $a1=array(0=>&quot;Cat&quot;,1=>&quot;Dog&quot;,2=>&quot;Horse&quot;); $a2=array(3=>&quot;Horse&quot;,4=>&quot;Dog&quot;,5=>&quot;Fish&quot;); print_r(array_diff($a1,$a2)); ?>  E.g:   Array ( [0] => Cat )  Output:   Array Functions
02/21/12 The  array_diff_assoc( arr1, arr2,… )  function compares two or more arrays, and returns an array with the keys and values from the first array, only if they are not present in any of the other arrays. Computes the difference of arrays with additional index check. Open Source Programming <?php $a1=array(0=>&quot;Cat&quot;,1=>&quot;Dog&quot;;,2=>&quot;Horse&quot;); $a2=array(0=>&quot;Rat&quot;,1=>&quot;Horse&quot;;,2=>&quot;Dog&quot;); $a3=array(0=>&quot;Horse&quot;,1=>&quot;Dog&quot;,2=>&quot;Cat&quot;); print_r(array_diff_assoc($a1,$a2,$a3));  ?>  E.g:   Array ( [0] => Cat [2] => Horse )  Output:   Array Functions
02/21/12 array_fill ( start,number,value   )  function returns an array filled with the values you describe where start is starting index,number defines number of entries. Open Source Programming <?php $a=array_fill(2,3,&quot;Dog&quot;); print_r($a);  ?>  E.g:   Array ( [2] => Dog [3] => Dog [4] => Dog )  Output:   Array Functions
02/21/12 The  array_flip ( array   )  function returns an array with all the original keys as values, and all original values as keys. Open Source Programming <?php $a=array(0=>&quot;Dog&quot;,1=>&quot;Cat&quot;,2=>&quot;Horse&quot;); print_r(array_flip($a)); ?>  E.g:   Array ( [Dog] => 0 [Cat] => 1 [Horse] => 2 )  Output:   Array Functions
02/21/12 The  array_key_exists( key,arr   )  function checks an array for a specified key, and returns true if the key exists and false is the key does not exist. Open Source Programming <?php $a=array(&quot;a&quot;=>&quot;Dog&quot;,&quot;b&quot;=>&quot;Cat&quot;); if (array_key_exists(&quot;a&quot;,$a))     echo &quot;Key exists!&quot;;   else     echo &quot;Key does not exist!&quot;;   ?>  E.g:   Key exists!  Output:   Array Functions
02/21/12 The  array_merge( array1,array2,array3... )  function merges one or more arrays into one array. If the input arrays have the same string keys, then the later value for that key will overwrite the previous one. If, however, the arrays contain numeric keys, the later value will  not  overwrite the original value, but will be appended.  Open Source Programming <?php $a1=array(&quot;a&quot;=>&quot;Horse&quot;,&quot;b&quot;=>&quot;Dog&quot;); $a2=array(&quot;c&quot;=>&quot;Cow&quot;,&quot;b&quot;=>&quot;Cat&quot;); print_r(array_merge($a1,$a2)); ?>  E.g:   Array ( [a] => Horse [b] => Cat [c] => Cow ) Output:   Array Functions
02/21/12 Open Source Programming <?php $a=array(0=>&quot;v&quot;,1=>&quot;h&quot;); $a1=array(1=>&quot;h&quot;,2=>&quot;g&quot;); print_r(array_merge($a,$a1))f; ?> E.g:   Array ( [0] => Horse [1] => Dog )  Output:   Array Functions
02/21/12 array_multisort( array1 ,  sortingorder ,  sorting   type ,  array2, array3   )  returns a sorted array. You can assign one or more arrays.  Open Source Programming <?php $a1=array(“Dog&quot;,&quot;Cat&quot;); $a2=array(&quot;Fido&quot;,&quot;Missy&quot;); array_multisort($a1,$a2); print_r($a1); print_r($a2); ?>  E.g:   Array ( [0] => Cat [1] => Dog ) Array ( [0] => Missy [1] => Fido )  Output:   Array Functions
02/21/12 Open Source Programming <?php  $a1=array(&quot;Dog&quot;,&quot;Dog&quot;,&quot;Cat&quot;); $a2=array(&quot;Pluto&quot;,&quot;Fido&quot;,&quot;Missy&quot;); array_multisort($a1,SORT_ASC,$a2,SORT_DESC); print_r($a1); print_r($a2);  ?>  E.g:   Array ( [0] => Cat [1] => Dog [2] => Dog )  Array ( [0] => Missy [1] => Pluto [2] => Fido )  Output:   Array Functions
02/21/12 The  array_pop( array )  function deletes the last element of an array.  Array_shift( array )  – removes an element at the beginning of the array Open Source Programming <?php $a=array(&quot;Dog&quot;,&quot;Cat&quot;,&quot;Horse&quot;); array_pop($a); print_r($a); array_shift($a); print_r($a); ?>  E.g:   Array ( [0] => Dog [1] => Cat )  Array ( [0] => Cat )  Output:   Array Functions
02/21/12 The  array_push( array,value1,value2... )  function inserts one or more elements to the end of an array.  Array_unshift( array )  – inserts an element at the beginning of the array Open Source Programming <?php $a=array(&quot;Dog&quot;,&quot;Cat&quot;); array_push($a,&quot;Horse&quot;,&quot;Bird&quot;); Print_r($a); array_unshift($a, “fish”); print_r($a); ?>  E.g:   Array ( [0] => Dog [1] => Cat [2] => Horse [3] => Bird )  Array ( [0] => fish [1]=>Dog [2] => Cat [3] => Horse [4] => Bird )  Output:   Array Functions
02/21/12 array_push — Push one or more elements onto the end of array Open Source Programming <?php $a=array(&quot;a&quot;=>&quot;Dog&quot;,&quot;b&quot;=>&quot;Cat&quot;); array_push($a,&quot;Horse&quot;,&quot;Bird&quot;); print_r($a); ?>  E.g:   Array ( [a] => Dog [b] => Cat [0] => Horse [1] => Bird )  Output:   Array Functions
02/21/12 array_rand( array,num )  function returns a random key from an array, or it returns an array of random keys if you specify that the function should return more than one key.  Open Source Programming <?php $a=array(&quot;a&quot;=>&quot;Dog&quot;,&quot;b&quot;=>&quot;Cat&quot;,&quot;c&quot;=>&quot;Horse&quot;); print_r(array_rand($a,1)); ?>  E.g:   b  Output:   Array Functions
02/21/12 The  array_reverse( array,preserve )  function returns an array in the reverse order. Open Source Programming <?php $a=array(&quot;a&quot;=>&quot;Dog&quot;,&quot;b&quot;=>&quot;Cat&quot;,&quot;c&quot;=>&quot;Horse&quot;); print_r(array_reverse($a)); ?>  E.g:   Array ( [c] => Horse [b] => Cat [a] => Dog )  Output:   Array Functions
02/21/12 The  array_search( value,array,strict   )  function search an array for a value and returns the key. Open Source Programming <?php $a=array(&quot;a&quot;=>&quot;Dog&quot;,&quot;b&quot;=>&quot;Cat&quot;,&quot;c&quot;=>&quot;Horse&quot;); echo array_search(&quot;Dog&quot;,$a); ?>  E.g:   a  Output:   Array Functions
02/21/12 The  array_slice( array,   start,   length,   preserve )  function returns selected parts of an array. Open Source Programming <?php $a=array(0=>&quot;Dog&quot;,1=>&quot;Cat&quot;,2=>&quot;Horse&quot;,3=>&quot;Bird&quot;); print_r(array_slice($a,1,2)); ?>  E.g:   Array ( [0] => Cat [1] => Horse )  Output:   Array Functions
02/21/12 The  array_splice( array,start,length,array )  function removes selected elements from an array and replaces it with new elements. The function also returns an array with the removed elements. Open Source Programming <?php $a1=array(0=>&quot;Dog&quot;,1=>&quot;Cat&quot;,2=>&quot;Horse&quot;,3=>&quot;Bird&quot;); $a2=array(0=>&quot;Tiger&quot;,1=>&quot;Lion&quot;); array_splice($a1,0,2,$a2); print_r($a1);  ?>  E.g:   Array ( [0] => Tiger [1] => Lion [2] => Horse [3] => Bird )  Output:   Array Functions
02/21/12 The  array_sum( array )  function returns the sum of all the values in the array. Open Source Programming <?php $a=array(0=>&quot;5&quot;,1=>&quot;15&quot;,2=>&quot;25&quot;); echo array_sum($a);  ?>  E.g:   45  Output:   Array Functions
02/21/12 The  arsort( array,sorttype )  function sorts an array by the values in reverse order. The values keep their original keys. Open Source Programming <?php $my_array = array(&quot;a&quot; => &quot;Dog&quot;, &quot;b&quot; => &quot;Cat&quot;, &quot;c&quot; => &quot;Horse&quot;); arsort($my_array); print_r($my_array); ?>  E.g:   Array ( [c] => Horse [a] => Dog [b] => Cat )  Output:   Array Functions
02/21/12 The  asort( array,sorttype )  function sorts an array by the values. The values keep their original keys  Open Source Programming <?php $my_array = array(&quot;a&quot; => &quot;Dog&quot;, &quot;b&quot; => &quot;Cat&quot;, &quot;c&quot; => &quot;Horse&quot;); asort($my_array); print_r($my_array); ?>  E.g:   Array ( [b] => Cat [a] => Dog [c] => Horse  )  Output:   Array Functions
02/21/12 The  krsort( array,sorttype )  function sorts an array by the keys in reverse order. The values keep their original keys. Open Source Programming <?php $my_array = array(&quot;a&quot; => &quot;Dog&quot;, &quot;b&quot; => &quot;Cat&quot;, &quot;c&quot; => &quot;Horse&quot;); krsort($my_array); print_r($my_array); ?>  E.g:   Array ( [c] => Horse [b] => Cat [a] => Dog  )  Output:   Array Functions
02/21/12 The  ksort( array,sorttype )  function sorts an array by the keys. The values keep their original keys. Open Source Programming <?php $my_array = array(&quot;a&quot; => &quot;Dog&quot;, &quot;b&quot; => &quot;Cat&quot;, &quot;c&quot; => &quot;Horse&quot;); ksort($my_array); print_r($my_array); ?>  E.g:   Array ( [a] => Dog [b] => Cat [c] => Horse  )  Output:   Array Functions
02/21/12 The  rsort( array )  function sorts an array by the values in reverse order. This function assigns new keys for the elements in the array. Existing keys will be removed.  Open Source Programming <?php $my_array = array(&quot;a&quot; => &quot;Dog&quot;, &quot;b&quot; => &quot;Cat&quot;, &quot;c&quot; => &quot;Horse&quot;); rsort($my_array); print_r($my_array); ?>  E.g:   Array ( [0] => Horse [1] => Dog [2] => Cat )  Output:   Array Functions
02/21/12 The  sort( array )  function sorts an array by the values. This function assigns new keys for the elements in the array. Existing keys will be removed.  Open Source Programming <?php $my_array = array(&quot;a&quot; => &quot;Dog&quot;, &quot;b&quot; => &quot;Cat&quot;, &quot;c&quot; => &quot;Horse&quot;); sort($my_array); print_r($my_array); ?>  E.g:   Array ( [0] => Cat [1] => Dog [2] => Horse )  Output:   Array Functions
02/21/12 Open Source Programming CASE_LOWER CASE_UPPER SORT_ASC SORT_DESC SORT_REGULAR SORT_NUMERIC SORT_STRING SORT_LOCALE_STRING COUNT_NORMAL COUNT_RECURSIVE Array Constants EXTR_OVERWRITE EXTR_SKIP EXTR_PREFIX_SAME EXTR_PREFIX_ALL EXTR_PREFIX_INVALID EXTR_PREFIX_IF_EXISTS EXTR_IF_EXISTS EXTR_REFS
02/21/12 The  count_chars( string,mode   )  function returns how many times an ASCII character occurs within a string and returns the information. Open Source Programming String Functions Array ( [32] => 1 [33] => 1 [72] => 1 [87] => 1 [100] => 1 [101] => 1 [108] => 3 [111] => 2 [114] => 1 )  Output:   <?php $str = &quot;Hello World!&quot;; print_r(count_chars($str,1)); ?>  E.g:
02/21/12 The different return  modes  are: 0  - an array with the ASCII value as key and number of occurrences as value 1  - an array with the ASCII value as key and number of occurrences as value, only lists occurrences greater than zero 2  - an array with the ASCII value as key and number of occurrences as value, only lists occurrences equal to zero are listed 3  - a string with all the different characters used 4  - a string with all the unused characters Open Source Programming String Functions
02/21/12 The  explode( separator, string, limit )  function breaks a string into an array. Open Source Programming Array ( [0] => Hello [1] => world. [2] => It's [3] => a [4] => beautiful [5] => day. )  Output:   String Functions <?php $str = &quot;Hello world. It's a beautiful day.&quot;; print_r (explode(&quot; &quot;,$str)); ?>  E.g:
02/21/12 The  implode( separator,array   )   &  join ( separator,array   )  function returns a string from the elements of an array.  Open Source Programming Hello World! Beautiful Day!  Output:   String Functions <?php $arr = array('Hello','World!','Beautiful','Day!'); echo implode(&quot; &quot;,$arr); ?>  E.g:
02/21/12 The  ltrim( string,charlist )  &  rtrim( string,charlist )  function will remove whitespaces or other predefined character from the left and right side of a string respectively.  The  soundex( string )  function calculates the soundex key of a string. The  str_shuffle( string )  function randomly shuffles all the characters of a string.  Open Source Programming String Functions
02/21/12 The  strlen ( string ) function returns the length of a string. Open Source Programming Length = 12  Output:   String Functions <?php $a= “hello World!”; echo “Length =  “, strlen($a); ?>  E.g:
02/21/12 The  strrev ( string ) reverses the given string. Open Source Programming Reverse of “hello World!” is !dlroW olleh Output:   String Functions <?php $a= “hello World!”; echo “Reverse of $a is “, strrev($a); ?>  E.g:
02/21/12 The  strtoupper ( string ) converts to upper case character The  strtolower ( string ) converts to lower case character Open Source Programming Upper of “hello World!” is HELLO WORLD! Lower of “hello World!” is hello world Output:   String Functions <?php $a= “hello World!”; echo “Upper of $a is “, strtoupper($a); echo “Lower of $a is “, strtolower($a); ?>  E.g:
02/21/12 The  strpos ( string,exp ) returns the numerical position of first appearance of exp.  The  strrpos ( string,exp ) returns the numerical position of last appearance of exp. Open Source Programming 2 9 Output:   String Functions <?php $a= “hello World!”; echo strpos($a,”l”),”<br>”; echo strrpos($a,”l”); ?>  E.g:
02/21/12 The  substr ( string,start,length ) function returns a sub string of the size “length” from the position of “start”. Open Source Programming lo  Output:   String Functions <?php $a= “hello World!”; echo substr($a,3,2); ?>  E.g:
02/21/12 The  substr_count ( string,substr ) counts number of times a  sub string occurred in given string. Open Source Programming 2  Output:   String Functions <?php $a= “hello Worlod!”; echo substr_count($a,”lo”); ?>  E.g:
02/21/12 The  substr_replace ( string,replacement,start,len ) replaces a portion of a string with a replacement string, beginning the substitution at a specified starting position and ending at a predefined replacement length. Open Source Programming heaaorld!  Output:   String Functions <?php $a= “hello World!”; echo substr_replace($a,”aa”,2,5); ?>  E.g:
02/21/12 The  ucfirst ( string ) converts the first character to upper case. The  ucwords ( string ) converts the first character of each word to upper case. Open Source Programming Hello world! Hello World! Output:   String Functions <?php $a= “hello world!”; echo ucfirst($a),”<br>”; echo ucwords($a);  ?>  E.g:
02/21/12 The  parse_str ( string,arr ) function parses a query string into variables. Open Source Programming 23 Kai Jim  Output:   String Functions <?php parse_str(&quot;id=23&name=Kai%20Jim&quot;); echo $id.&quot;<br />&quot;; echo $name; ?>  E.g:
02/21/12 The  str_replace( find,replace,string,count   )  function replaces some characters with some other characters in a string. Note:  str_ireplace()  – for case sensitive Open Source Programming Array ( [0] => blue [1] => pink [2] => green [3] => yellow ) Replacements: 1  Output:   String Functions <?php $arr = array(&quot;blue&quot;,&quot;red&quot;,&quot;green&quot;,&quot;yellow&quot;); print_r(str_ireplace(&quot;RED&quot;,&quot;pink&quot;,$arr,$i)); echo &quot;Replacements: $i&quot;; ?>  E.g:
02/21/12 The  str_pad( string,length,padchar,padtype )  function pads a string to a new length.  Open Source Programming .........Hello World  Output:   String Functions <?php $str = &quot;Hello World&quot;; echo str_pad($str,20,&quot;.&quot;,STR_PAD_LEFT); ?>  E.g:
02/21/12 The  str_split( string,length   )  function splits a string into an array. Default length is 1. Open Source Programming Array ( [0] => Hel [1] => lo )  Output:   String Functions <?php print_r(str_split(&quot;Hello&quot;,3)); ?> E.g:
02/21/12 The  str_word_count( string )  function counts the number of words in a string. Open Source Programming 2 Output:   String Functions <?php echo str_word_count(&quot;Hello world!&quot;); ?> E.g:
02/21/12 The  strcasecmp( string1,string2 )  function compares two strings as case insensitive.  Strcmp( string1,string2 )  compares as case sensitive. This function returns: 0  - if the two strings are equal  < 0  - if string1 is less than string2  > 0  - if string1 is greater than string2  Open Source Programming 0 1 Output:   String Functions <?php echo strcasecmp(&quot;Hello world!&quot;,&quot;HELLO WORLD!&quot;); echo “<br>”; echo strcmp(&quot;Hello world!&quot;,&quot;HELLO WORLD!&quot;); ?> E.g:
02/21/12 The  stripos( string,find,start )  function returns the position of the first occurrence of a string inside another string. But doesn’t check for case sensitivity. In strpos it’s d same but check for case sensitivity. Strpos( string,find,start )  – case sensitive. If the string is not found, this function returns FALSE. Open Source Programming 6 Output:   String Functions <?php echo stripos(&quot;Hello world!&quot;,&quot;WO&quot;); ?> E.g:
02/21/12 The  stristr( string,exp )  function searches for the first occurrence of a string inside another string. This function returns the rest of the string (from the matching point), or FALSE, if the string to search for is not found Open Source Programming World! Have a nice day Output:   String Functions <?php echo stristr(&quot;Hello world! Have a nice day&quot;,&quot;WORLD&quot;); ?> E.g:
02/21/12 Boolean  Checkdate( day,month,year )  – used to check the given parameters are a valid date. Date( formatstring ) -  The date() function returns a string representation of the current date and/or time formatted according to the instructions specified by a predefined format. Array  Getdate ( int   timestamp )  – returns array of datetime components Time()  – returns time stamp Mktime( int   h,int min, int sec, int day, int mnth, int yr )  – create a date and time Open Source Programming Date Functions
02/21/12 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Open Source Programming Math Functions
02/21/12 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Open Source Programming Super Globals
02/21/12 $_SERVER: The $_SERVER super global contains information created by the Web server and offers a bevy of information regarding the server and client configuration and the current request environment. $_GET & $_POST: The $_GET and $_POST super globals are used to retrieve information from forms, like user input. $_COOKIE:   The $_COOKIE super global stores information passed into the script through HTTP cookies Open Source Programming Super Globals
02/21/12 $_ENV:   The $_ENV super global offers information regarding the PHP parser’s underlying server environment. $_SESSION:   The $_SESSION super global contains information regarding all session variables $_FILES: The $_FILES super global contains information regarding data uploaded to the server via the POST method. This super global is a tad different from the others. Open Source Programming Super Globals
02/21/12 ,[object Object],[object Object],[object Object],[object Object],Open Source Programming User Defined Functions
02/21/12 Function E.g . <?php function generateFooter() { echo &quot;Copyright 2007 W. Jason Gilmore&quot;; } // Once defined,  call the function likes so: generateFooter(); // function calling ?> Output: Copyright 2007 W. Jason Gilmore Open Source Programming User Defined Functions
02/21/12 ,[object Object],[object Object],[object Object],[object Object],Open Source Programming User Defined Functions
02/21/12 Function with argument: <?php function writeName ($fname ) { echo $fname . &quot; Refsnes.<br />&quot;; } echo &quot;My name is &quot;; writeName(&quot; Kai Jim &quot;); echo &quot;My sister's name is &quot;; writeName(&quot; Hege &quot;); echo &quot;My brother's name is &quot;; writeName(&quot; Stale &quot;); ?> Open Source Programming Output: My name is Kai Jim Refsnes. My sister's name is Hege Refsnes. My brother's name is Stale Refsnes.  User Defined Functions  Formal Argument Fn. Call with Actual Argument
02/21/12 Function with arguments & return value: <?php function calculateAmt ($cost, $num ) { return  ($cost * $num);  } $price=10; $tot=5; Echo “ Total Amount “, calculateAmt($price, $tot); ?> Open Source Programming Output: Total Amount 50 User Defined Functions
02/21/12 Fn. Call by Ref.: <?php $cost = 20.99; $tax = 0.0575; function calculateCost( & $cost, $tax) { // Modify the $cost variable $cost = $cost + ($cost * $tax); // Perform some random change to the $tax variable. $tax += 4; } Echo “(bfr fn call) Cost is $cost <br>”; calculateCost($cost, $tax); Echo &quot;Tax is $tax*100 <br>&quot;; Echo “(aft fn call) Cost is: $cost”; ?> Open Source Programming Output: (bfr fn call) Cost is 20.99 Tax is  5.75 (aft fn call) Cost is: 22.20 User Defined Functions
02/21/12 ,[object Object],[object Object],[object Object],Open Source Programming User Defined Functions
02/21/12 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Open Source Programming Output: Temp is: 10 User Defined Functions
02/21/12 Open Source Programming PHP Form Handling < form   method  = POST  action  = form.php> Name: < input   type  =text  name  =  fname >  <br > Age: < input   type  = text  name  =  age > < br > < input   type  = submit  value  = submit> </ form > HTML Code  (Form.html) <?php $a = $_POST[' fname ']; $b = $_POST[' age ']; echo &quot;Welcome Mr./Ms. $a. You are $b years old &quot;; ?> PHP Code  (form.php)
02/21/12 Open Source Programming HTML Browser Result PHP Form Handling
02/21/12 Open Source Programming Open Source Programming 1.  The application attempts something. 2.   If the attempt fails, the exception-handling feature throws an exception. 3. The assigned handler catches the exception and performs any necessary tasks. 4 . The exception-handling feature cleans up any resources consumed during the attempt. In PHP, Exception handling can be done by  try …throw… catch . Exception Handling PHP
02/21/12 Open Source Programming Open Source Programming Exception handling syntax: Try { statement block; if goes wrong throw new exception(error message) }  catch (exception $E) {  echo $E.getMessage(); } Exception Handling PHP
02/21/12 <?php $a=10; $b=0; try { if ($b == 0) throw new exception(&quot;Divide by zero error&quot;); $c = $a/$b;  echo &quot; $a&quot;,&quot; / &quot;,&quot;$b = &quot;, $a/$b; } catch(Exception $e) {  echo $e->getMessage(); } ?> Open Source Programming Output: Divide by zero error Exception Handling in PHP
02/21/12 Open Source Programming ,[object Object],[object Object],[object Object],[object Object],Object Oriented PHP  - Class
02/21/12 Open Source Programming E.g.: <?php class  SimpleClass {     // property declaration      public  $var = ‘Hello';     // method declaration     public function displayVar()   {         echo $this->var;     } $obj1 =  new  SimpleClass(); $Obj1->displayVar(); } ?>  ,[object Object],[object Object],[object Object],[object Object],Object Oriented PHP  - Object
02/21/12 Open Source Programming ,[object Object],[object Object],[object Object],[object Object],[object Object],Inheritance
02/21/12 <?php class ExtendClass extends SimpleClass {     // Redefine the parent method     function displayVar()     {         echo &quot;Extending class&quot;;         parent::displayVar();     } } $extended = new ExtendClass(); $extended->displayVar(); ?>  Open Source Programming Extending class Hello  E.G . Output: Inheritance
02/21/12 Open Source Programming ,[object Object],[object Object],[object Object],[object Object],Constructors & Destructors
02/21/12 E.g . <?php class BaseClass {    function __construct() {        print &quot;In BaseClass constructor&quot;;    } } class SubClass extends BaseClass {    function __construct() {        parent::__construct();        print &quot;In SubClass constructor&quot;;    } } $obj = new BaseClass(); $obj = new SubClass(); ?>  Output: In BaseClass constructor In BaseClass constructor In SubClass constructor Open Source Programming Constructors & Destructors
02/21/12 Open Source Programming ,[object Object],[object Object],[object Object],Overloading
02/21/12 E.g. <?php class foo { public function printItem($string)  { echo 'Foo: ' . $string . PHP_EOL; } public function printPHP()  { echo 'PHP is great.' . PHP_EOL; } } class c extends foo { public function printItem($string)  { echo &quot;Extending from FOO&quot;; parent::printItem(&quot;this is gud&quot;); } } $foo = new foo(); $c  = new c(); $foo->printItem('baz'); ' $foo->printPHP();  $c->printItem('from C'); $c->printPHP(); ?> Foo: baz  PHP is great. Extending from FOO Foo: this is gud PHP is great.  Output: Open Source Programming Overloading
02/21/12 Open Source Programming Can insert the content of one PHP file into another PHP file before the server executes it, with the  include()  or  require()  function. The include() function takes all the content in a specified file and includes it in the current file. Files are included based on the file path given . The two functions are identical in every way, except how they handle errors: 1. include() generates a warning, but the script will continue execution  2. require() generates a fatal error, and the script will stop  E.g. <?php include(&quot;wrongFile.php&quot;); echo &quot;Hello World!&quot;; ?> Output: Error Message Hello World Include & Require
02/21/12 Open Source Programming E.g. <?php require(&quot;wrongFile.php&quot;); echo &quot;Hello World!&quot;; ?> Output: Error Message Include & Require
02/21/12 Open Source Programming ,[object Object],[object Object],[object Object],[object Object],E.g. <?php $ourFileName = &quot;testFile.txt&quot;; $ourFileHandle = fopen($ourFileName, ‘w‘) ?> Files
02/21/12 Open Source Programming ,[object Object],Files
02/21/12 File closing can be done by fclose(fp); E.g. <?php $ourFileName = &quot;testFile.txt&quot;; $ourFileHandle = fopen($ourFileName, ‘w') or die(&quot;can't open file&quot;); fclose($ourFileHandle); ?> Files
02/21/12 Open Source Programming 1)  fopen(filename,mode)  - used for opening a file with specific mode. 2)  fclose(fp)  - used to close the file. (fp -> filepointer) 3)  feof(fp)  - used to find the End of File 4)  fgetc(fp)  - Gets character from file pointer 5)  fgets(fp)  - Gets a line from file pointer 6)  fread(fp,size)  - Binary-safe file read 7)  fscanf(fp,format)  - Parses input from a file according to a format 8)  fwrite(fp,string)  - Binary-safe file write 9)  file_put_contents(fp,string)  - Write a string to a file 10)  file_get_contents(fp)  - Reads entire file into a string 11)  file(fp)  - Reads entire file into an array 12)  file_exists(fp)  - Checks whether a file or directory exists Some File Functions
02/21/12 Open Source Programming 13)  is_readable(fp)  - Tells whether the filename is readable 14)  is_writable(fp)  - Tells whether the filename is writable 15)  is_file(path)  - Tells whether the filename is a regular file 16)  is_dir(path)  - Tells whether the filename is a directory 17)  is_link(path)  - Tells whether the filename is a symbolic link 18)  readlink(path)  - Returns the target of a symbolic link 19)  readdir  - Read entry from directory handle 20)  glob  - Find pathnames matching a pattern 21)  filesize(fp)  - Gets file size 22)  filetype(fp)  - Gets file type 23)  fprintf(fp,format)  - Write a formatted string to a stream 24)  fstat(fp)  - Gets information about a file using an open file pointer Some File Functions
02/21/12 Open Source Programming <?php $myFile = &quot;testFile.txt&quot;; $fh = fopen($myFile, 'w') or die(&quot;can't open file&quot;); $stringData = &quot;Bobby Bopper&quot;; fwrite($fh, $stringData); $stringData = &quot;Tracy Tanner&quot;; fwrite($fh,$stringData); fclose($fh);  ?> E.g. <?php $ourFileName = &quot;testFile.txt&quot;; $ourFileHandle = fopen($ourFileName, ‘w') or die(&quot;can't open file&quot;); ?> File Write
02/21/12 Open Source Programming E.g.   <?php // get contents of a file into a string $filename = &quot;testfile.txt&quot;; $handle = fopen($filename, &quot;r&quot;); //$contents = fread($handle, filesize($filename)); while (!feof($handle)) echo fgetc($handle),&quot;<br>&quot;; //print_r(&quot;$contents&quot;); fclose($handle); ?>  Output: Bobby Bopper Tracy Tanner  File Read
02/21/12 Open Source Programming E.g.   <?php $myFile = &quot;testFile.txt&quot;; $fh = fopen($myFile, 'a+') or die(&quot;can't open file&quot;); $stringData = &quot;new1&quot;; fwrite($fh, $stringData); $stringData = &quot;new2&quot;; fwrite($fh, $stringData); fclose($fh);  ?> Output: Bobby Bopper Tracy Tannernew1new2  File Append
02/21/12
02/21/12

More Related Content

What's hot (18)

PHP programmimg
PHP programmimgPHP programmimg
PHP programmimg
 
PHP Project PPT
PHP Project PPTPHP Project PPT
PHP Project PPT
 
PHP Presentation
PHP PresentationPHP Presentation
PHP Presentation
 
Php ppt
Php pptPhp ppt
Php ppt
 
web Based Application Devlopment using PHP
web Based Application Devlopment using PHPweb Based Application Devlopment using PHP
web Based Application Devlopment using PHP
 
Advanced PHP Web Development Tools in 2015
Advanced PHP Web Development Tools in 2015Advanced PHP Web Development Tools in 2015
Advanced PHP Web Development Tools in 2015
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
 
PHP ITCS 323
PHP ITCS 323PHP ITCS 323
PHP ITCS 323
 
PHP
PHPPHP
PHP
 
Raisa anthony web programming 1st week
Raisa anthony   web programming 1st weekRaisa anthony   web programming 1st week
Raisa anthony web programming 1st week
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
 
Guidelines php 8 gig
Guidelines php 8 gigGuidelines php 8 gig
Guidelines php 8 gig
 
PHP
PHPPHP
PHP
 
Codeigniter
CodeigniterCodeigniter
Codeigniter
 
Software Design
Software DesignSoftware Design
Software Design
 
PHP Introduction ( Fedora )
PHP Introduction ( Fedora )PHP Introduction ( Fedora )
PHP Introduction ( Fedora )
 
Php technical presentation
Php technical presentationPhp technical presentation
Php technical presentation
 
Advantages of Choosing PHP Web Development
Advantages of Choosing PHP Web DevelopmentAdvantages of Choosing PHP Web Development
Advantages of Choosing PHP Web Development
 

Similar to Osp ii presentation

Lamp technology
Lamp technologyLamp technology
Lamp technology2tharan21
 
chapter 5 Server-Side Scripting (PHP).pdf
chapter 5 Server-Side Scripting (PHP).pdfchapter 5 Server-Side Scripting (PHP).pdf
chapter 5 Server-Side Scripting (PHP).pdfburasyacob012
 
Nadhiya lamp
Nadhiya lampNadhiya lamp
Nadhiya lampNadhi ya
 
lamp technology
lamp technologylamp technology
lamp technologyDeepa
 
Deepa ppt about lamp technology
Deepa ppt about lamp technologyDeepa ppt about lamp technology
Deepa ppt about lamp technologyDeepa
 
Full Stack Web Development: Vision, Challenges and Future Scope
Full Stack Web Development: Vision, Challenges and Future ScopeFull Stack Web Development: Vision, Challenges and Future Scope
Full Stack Web Development: Vision, Challenges and Future ScopeIRJET Journal
 
Open Source Technology and Web Scripting
Open Source Technology and Web ScriptingOpen Source Technology and Web Scripting
Open Source Technology and Web ScriptingCritarac Technologies
 
.Net Development Services VS | PHP Development Services
.Net Development Services  VS | PHP Development Services.Net Development Services  VS | PHP Development Services
.Net Development Services VS | PHP Development ServicesWorth Studios Pvt. Ltd.
 
PHP and MySQL
PHP and MySQLPHP and MySQL
PHP and MySQLbmani
 
Web Development in Perl
Web Development in PerlWeb Development in Perl
Web Development in PerlNaveen Gupta
 
Oss the freedom dpm 2018
Oss the freedom dpm 2018Oss the freedom dpm 2018
Oss the freedom dpm 2018BIT DURG
 

Similar to Osp ii presentation (20)

Lamp
LampLamp
Lamp
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Lamp technology
Lamp technologyLamp technology
Lamp technology
 
chapter 5 Server-Side Scripting (PHP).pdf
chapter 5 Server-Side Scripting (PHP).pdfchapter 5 Server-Side Scripting (PHP).pdf
chapter 5 Server-Side Scripting (PHP).pdf
 
PHP
PHPPHP
PHP
 
Nadhiya lamp
Nadhiya lampNadhiya lamp
Nadhiya lamp
 
lamp technology
lamp technologylamp technology
lamp technology
 
Deepa ppt about lamp technology
Deepa ppt about lamp technologyDeepa ppt about lamp technology
Deepa ppt about lamp technology
 
Full Stack Web Development: Vision, Challenges and Future Scope
Full Stack Web Development: Vision, Challenges and Future ScopeFull Stack Web Development: Vision, Challenges and Future Scope
Full Stack Web Development: Vision, Challenges and Future Scope
 
Word press
Word pressWord press
Word press
 
Open Source Technology and Web Scripting
Open Source Technology and Web ScriptingOpen Source Technology and Web Scripting
Open Source Technology and Web Scripting
 
.Net Development Services VS | PHP Development Services
.Net Development Services  VS | PHP Development Services.Net Development Services  VS | PHP Development Services
.Net Development Services VS | PHP Development Services
 
Apache Ppt
Apache PptApache Ppt
Apache Ppt
 
Webtechnologies
Webtechnologies Webtechnologies
Webtechnologies
 
Programming language
Programming languageProgramming language
Programming language
 
PHP and MySQL
PHP and MySQLPHP and MySQL
PHP and MySQL
 
Web Development in Perl
Web Development in PerlWeb Development in Perl
Web Development in Perl
 
Lamp Zend Security
Lamp Zend SecurityLamp Zend Security
Lamp Zend Security
 
Oss the freedom dpm 2018
Oss the freedom dpm 2018Oss the freedom dpm 2018
Oss the freedom dpm 2018
 

Recently uploaded

Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 

Recently uploaded (20)

Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 

Osp ii presentation

  • 1. 02/21/12 Open Source Programming
  • 2. 02/21/12 Open Source Programming Introduction Unit – I Open source Programming PHP, Apache, MySQL, Postgress, SQL and Perl- Overview of PHP – Variables, operators, Constants, control structures arrays, Functions, classes – Handling files.
  • 3. 02/21/12 By allowing the open exchange of information, programmers from all over the world contribute to make a truly powerful and efficient piece of software without royalties or fees. Open Source Programming What is Open source
  • 4.
  • 5.
  • 6. 02/21/12 Apache — HTTP web server Tomcat web server — web container Mediawiki — wiki server software Alfresco, TYPO3 — content management system RenovatioCMS — content management system Joomla — content management system Drupal — content management system provides a collaborative environment for social networking sites, corporate Web sites, intranets, e-commerce applications and discussion sites. Open Source Programming OSP Software - Server
  • 7. 02/21/12 WordPress — blog software MongoDB — document-oriented, non-relational database Moodle — course management system or virtual learning environment openSIS — open source Student Information System Open Source Programming OSP Software
  • 8. 02/21/12 osCommerce — allows store owners to setup, run, and maintain online stores with minimum effort and with no costs P eaZip — File archiver Mozilla Firefox — web browser OpenOffice.org — office suite Stockfish — chess engine series, one of the strongest chess programs 7-Zip – File Archiver Open Source Programming OSP Software
  • 9. 02/21/12 PHP — Hypertext Preprocessor Ruby,Tcl/Tk PERL & Python — Interpreted Dynamic Language MySQL — Data Base Open Source Programming OSP Software (Others)
  • 10.
  • 11.
  • 13.
  • 14.
  • 15.
  • 16. 02/21/12 Open Source Programming AMP as Restaurant MySQL – This is Stockroom of ingredients.
  • 17.
  • 18. 02/21/12 GNU General Public License (GPL) GNU Library or &quot;Lesser&quot; General Public License (LGPL) MIT license (MIT) Mozilla Public License 2.0 (MPL-2.0) Common Development and Distribution License (CDDL-1.0) Eclipse Public License (EPL-1.0)
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24. 02/21/12 Open Source Programming CLIENT WEB SERVER HTTP Request (url) <HTML> <?php PHP code ?> </HTML> Gets Page <HTML> <B>Hello</B> </HTML> Interprets the PHP code Server response How it works? Browser creates the web page
  • 25.
  • 26.
  • 27. 02/21/12 Open Source Programming PHP is denoted in the page with opening and closing tags as follows: <?php //php code ; ?> PHP Syntax
  • 28. 02/21/12 <HTML> <HEAD> <TITLE> My First PHP Program </TITLE> <h1> </HEAD> <BODY> <?php echo “I’m a PHP Program.”; ?> </BODY> </HTML> Open Source Programming Code PHP Programs Result
  • 29. 02/21/12 <?php $name=“VIT UNIVERSITY”; echo ‘My name is ‘,$name; ?> Open Source Programming Code PHP Programs Result
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35. 02/21/12 $MyStrVal = &quot; This is an example of a string value &quot;; $MyIntVal = 145665; // An integer value $MyBoolval = True; // A Boolean value can either be True or False $MyFloatVal=2346.45 // A float value $MyArrVal[0] = &quot;My&quot;; //A array containing three elements $MyArrVal[1] = &quot;First&quot;; $MyArrVal[2] = &quot;Array&quot;; Open Source Programming Variables (cont)
  • 36. 02/21/12 Open Source Programming In PHP, Variable type can be changed by Settype Syntax: Settype(Variablename, “newDataType”); E.g. $pi = 3.14 //float Settype($pi,”string”); //now string – “3.14” Settype($pi,”integer”);// now integer - 3 Settype Settype
  • 37. 02/21/12 Open Source Programming Syntax: Gettype(Variablename); E.g. $pi = 3.14; //float print gettype($pi); Print “---$pi <br>”; Settype($pi,”string”); print gettype($pi); Print “---$pi <br>”; Settype($pi,”integer”); print gettype($pi); Print “---$pi <br>”; In PHP, Variable type and can know by Gettype . Settype & Gettype
  • 38.
  • 39.
  • 40. 02/21/12 Logical Operator Open Source Programming Operators (cont) Comparison Operator And Or ! Xor && ( high precedence) || ( high precedence) == != < > <= >= === (identical)
  • 41.
  • 42. 02/21/12 Open Source Programming 1. Echo & Print() is the common method in outputting data. Since it is a language construct, echo doesn’t require parenthesis like print(). 2. Output Text Usage: <?php echo “Hello World”; print(“Hello World”); // prints out Hello World ?> Output in PHP
  • 43. 02/21/12 Open Source Programming 3. Output the value of a PHP variable: <?php echo $hits; // prints out the number of hits print ($hits); // returns a value if print process success. ?> 4. Can use “<br>” , to print in next line: <?php echo $a , “<br>”, $b ; // prints a & b in separate lines ?> Output in PHP
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51. 02/21/12 Open Source Programming <?php $name[ ’firstname’ ] = “Albert”; $name[ ’lastname’ ] = “Einstein”; $name[ ’age’ ] = 124; ?> <?php $flavor[] = ‘blue rasberry’; $flavor[] = ‘root beer’; $flavor[] = ‘pineapple’; ?> Array with Implicit key Array with Explicit key Arrays
  • 52. 02/21/12 Open Source Programming Array of arrays is called as multidimensional arrays. $Student = array ( &quot;0&quot;=> array (&quot;name&quot;=>&quot;James&quot;, &quot;sex&quot;=>&quot;Male&quot;, &quot;age&quot;=>&quot;28&quot;), &quot;1&quot;=> array (&quot;name&quot;=>&quot;John&quot;, &quot;sex&quot;=>&quot;Male&quot;, &quot;age&quot;=>&quot;25&quot;), &quot;2&quot;=> array (&quot;name&quot;=>&quot;Susan&quot;, &quot;sex&quot;=>&quot;Female&quot;, &quot;age&quot;=>&quot;24&quot;)); $student[“1&quot;][“name&quot;] – returns John Multidimensional Arrays
  • 53. 02/21/12 $u= array ( &quot;0&quot;=> array (&quot;name&quot;=>&quot;James&quot;, &quot;sex&quot;=>&quot;Male&quot;, &quot;age&quot;=>&quot;28&quot;), &quot;1&quot;=> array (&quot;name&quot;=>&quot;John&quot;, &quot;sex&quot;=>&quot;Male&quot;, &quot;age&quot;=>&quot;25&quot;), &quot;2&quot;=> array (&quot;name&quot;=>&quot;Susan&quot;, &quot;sex&quot;=>&quot;Female&quot;, &quot;age&quot;=>&quot;24&quot;)); foreach ($u as $key=>$value) { echo &quot;$key is $value&quot;; echo &quot;The actual user is $key.<br/>&quot;; foreach ($value as $iKey => $iValue) { echo &quot; ---> $iKey -> $iValue <br/>&quot;; } } ?>
  • 54. 02/21/12 Output : 0 is Array The actual user is 0. ---> name -> James ---> sex -> Male ---> age -> 28 1 is Array The actual user is 1. ---> name -> John ---> sex -> Male ---> age -> 25 2 is Array The actual user is 2. ---> name -> Susan ---> sex -> Female ---> age -> 24
  • 55. 02/21/12 <html> <body> <FORM ACTION =“arr.php&quot; METHOD = &quot;post&quot;> ur name <INPUT TYPE=&quot;text&quot; NAME=&quot;ur name&quot;><br> cost <INPUT TYPE=&quot;text&quot; NAME=&quot;cost&quot;><br> days <INPUT TYPE=&quot;text&quot; NAME=&quot;days&quot;><br> <INPUT TYPE=&quot;submit&quot;name=&quot;submit&quot;><br> <?php if(isset($_POST['submit'])) { $d[0]=$_POST['cost']; $d[1]=$_POST['days']; $d[2]=$d[0]+$d[1]; echo &quot;output <INPUT TYPE=text value=$d[2]>&quot;; foreach($d as $v) echo &quot;output <INPUT TYPE=text value=$v>&quot; } ?> </body> </form> </html>
  • 56. 02/21/12 Functions: A function is a block of code that is not immediately executed but can be called by scripts whenever needs. Functions can be built-in or user-defined . They can require information to be passed to them and usually return a value. Open Source Programming Functions
  • 57. 02/21/12 Open Source Programming <?php $a=array(&quot;a&quot;=>&quot;Dog&quot;,&quot;b&quot;=>&quot;Cat&quot;,&quot;c&quot;=>&quot;Horse&quot;); print_r($a); ?> Array ( [a] => Dog [b] => Cat [c] => Horse ) Array( key=>value ) – Creates an array with keys and values Output: E.g.: Array Functions
  • 58. 02/21/12 Open Source Programming array_chunk( array,size,preserve_key ) - splits an array into chunks of new arrays Array Functions
  • 59. 02/21/12 Array ( [0] => Array ( [0] => Cat [1] => Dog ) [1] => Array ( [0] => Horse [1] => Cow ) ) Output: <?php $a=array(&quot;a&quot;=>&quot;Cat&quot;,&quot;b&quot;=>&quot;Dog&quot;,&quot;c&quot;=>&quot;Horse&quot;,&quot;d&quot;=>&quot;Cow&quot;); print_r(array_chunk($a,2)); ?> E.g.: 1 Open Source Programming Array Functions
  • 60. 02/21/12 Array ( [0] => Array ( [a] => Cat [b] => Dog ) [1] => Array ( [c] => Horse [d] => Cow ) ) Output: <?php $a=array(&quot;a&quot;=>&quot;Cat&quot;,&quot;b&quot;=>&quot;Dog&quot;,&quot;c&quot;=>&quot;Horse&quot;,&quot;d&quot;=>&quot;Cow&quot;); print_r(array_chunk($a,2,true)); ?> E.g.: 2 Open Source Programming Array Functions
  • 61. 02/21/12 array_combine( array1,array2 ) creates an array by combining two other arrays, where the first array is the keys, and the other array is the values. Open Source Programming Array Functions Array ( [a] => Cat [b] => Dog [c] => Horse [d] => Cow ) Output: <?php $a1=array(&quot;a&quot;,&quot;b&quot;,&quot;c&quot;,&quot;d&quot;); $a2=array(&quot;Cat&quot;,&quot;Dog&quot;,&quot;Horse&quot;,&quot;Cow&quot;); print_r(array_combine($a1,$a2)); ?> E.g.:
  • 62. 02/21/12 array_count_values( array ) returns an array, where the keys are the original array's values, and the values is the number of occurrences. Open Source Programming <?php $a=array(&quot;Cat&quot;,&quot;Dog&quot;,&quot;Horse&quot;,&quot;Dog&quot;); print_r(array_count_values($a)); ?> E.g: Array ( [Cat] => 1 [Dog] => 2 [Horse] => 1 ) Output: Array Functions
  • 63. 02/21/12 array_diff( arr1,arr2,… ) function compares two or more arrays, and returns an array with the keys and values from the first array, only if the value is not present in any of the other arrays. Open Source Programming <?php $a1=array(0=>&quot;Cat&quot;,1=>&quot;Dog&quot;,2=>&quot;Horse&quot;); $a2=array(3=>&quot;Horse&quot;,4=>&quot;Dog&quot;,5=>&quot;Fish&quot;); print_r(array_diff($a1,$a2)); ?> E.g: Array ( [0] => Cat ) Output: Array Functions
  • 64. 02/21/12 The array_diff_assoc( arr1, arr2,… ) function compares two or more arrays, and returns an array with the keys and values from the first array, only if they are not present in any of the other arrays. Computes the difference of arrays with additional index check. Open Source Programming <?php $a1=array(0=>&quot;Cat&quot;,1=>&quot;Dog&quot;;,2=>&quot;Horse&quot;); $a2=array(0=>&quot;Rat&quot;,1=>&quot;Horse&quot;;,2=>&quot;Dog&quot;); $a3=array(0=>&quot;Horse&quot;,1=>&quot;Dog&quot;,2=>&quot;Cat&quot;); print_r(array_diff_assoc($a1,$a2,$a3)); ?> E.g: Array ( [0] => Cat [2] => Horse ) Output: Array Functions
  • 65. 02/21/12 array_fill ( start,number,value ) function returns an array filled with the values you describe where start is starting index,number defines number of entries. Open Source Programming <?php $a=array_fill(2,3,&quot;Dog&quot;); print_r($a); ?> E.g: Array ( [2] => Dog [3] => Dog [4] => Dog ) Output: Array Functions
  • 66. 02/21/12 The array_flip ( array ) function returns an array with all the original keys as values, and all original values as keys. Open Source Programming <?php $a=array(0=>&quot;Dog&quot;,1=>&quot;Cat&quot;,2=>&quot;Horse&quot;); print_r(array_flip($a)); ?> E.g: Array ( [Dog] => 0 [Cat] => 1 [Horse] => 2 ) Output: Array Functions
  • 67. 02/21/12 The array_key_exists( key,arr ) function checks an array for a specified key, and returns true if the key exists and false is the key does not exist. Open Source Programming <?php $a=array(&quot;a&quot;=>&quot;Dog&quot;,&quot;b&quot;=>&quot;Cat&quot;); if (array_key_exists(&quot;a&quot;,$a))     echo &quot;Key exists!&quot;;   else     echo &quot;Key does not exist!&quot;;   ?> E.g: Key exists! Output: Array Functions
  • 68. 02/21/12 The array_merge( array1,array2,array3... ) function merges one or more arrays into one array. If the input arrays have the same string keys, then the later value for that key will overwrite the previous one. If, however, the arrays contain numeric keys, the later value will not overwrite the original value, but will be appended. Open Source Programming <?php $a1=array(&quot;a&quot;=>&quot;Horse&quot;,&quot;b&quot;=>&quot;Dog&quot;); $a2=array(&quot;c&quot;=>&quot;Cow&quot;,&quot;b&quot;=>&quot;Cat&quot;); print_r(array_merge($a1,$a2)); ?> E.g: Array ( [a] => Horse [b] => Cat [c] => Cow ) Output: Array Functions
  • 69. 02/21/12 Open Source Programming <?php $a=array(0=>&quot;v&quot;,1=>&quot;h&quot;); $a1=array(1=>&quot;h&quot;,2=>&quot;g&quot;); print_r(array_merge($a,$a1))f; ?> E.g: Array ( [0] => Horse [1] => Dog ) Output: Array Functions
  • 70. 02/21/12 array_multisort( array1 , sortingorder , sorting type , array2, array3 ) returns a sorted array. You can assign one or more arrays. Open Source Programming <?php $a1=array(“Dog&quot;,&quot;Cat&quot;); $a2=array(&quot;Fido&quot;,&quot;Missy&quot;); array_multisort($a1,$a2); print_r($a1); print_r($a2); ?> E.g: Array ( [0] => Cat [1] => Dog ) Array ( [0] => Missy [1] => Fido ) Output: Array Functions
  • 71. 02/21/12 Open Source Programming <?php $a1=array(&quot;Dog&quot;,&quot;Dog&quot;,&quot;Cat&quot;); $a2=array(&quot;Pluto&quot;,&quot;Fido&quot;,&quot;Missy&quot;); array_multisort($a1,SORT_ASC,$a2,SORT_DESC); print_r($a1); print_r($a2); ?> E.g: Array ( [0] => Cat [1] => Dog [2] => Dog ) Array ( [0] => Missy [1] => Pluto [2] => Fido ) Output: Array Functions
  • 72. 02/21/12 The array_pop( array ) function deletes the last element of an array. Array_shift( array ) – removes an element at the beginning of the array Open Source Programming <?php $a=array(&quot;Dog&quot;,&quot;Cat&quot;,&quot;Horse&quot;); array_pop($a); print_r($a); array_shift($a); print_r($a); ?> E.g: Array ( [0] => Dog [1] => Cat ) Array ( [0] => Cat ) Output: Array Functions
  • 73. 02/21/12 The array_push( array,value1,value2... ) function inserts one or more elements to the end of an array. Array_unshift( array ) – inserts an element at the beginning of the array Open Source Programming <?php $a=array(&quot;Dog&quot;,&quot;Cat&quot;); array_push($a,&quot;Horse&quot;,&quot;Bird&quot;); Print_r($a); array_unshift($a, “fish”); print_r($a); ?> E.g: Array ( [0] => Dog [1] => Cat [2] => Horse [3] => Bird ) Array ( [0] => fish [1]=>Dog [2] => Cat [3] => Horse [4] => Bird ) Output: Array Functions
  • 74. 02/21/12 array_push — Push one or more elements onto the end of array Open Source Programming <?php $a=array(&quot;a&quot;=>&quot;Dog&quot;,&quot;b&quot;=>&quot;Cat&quot;); array_push($a,&quot;Horse&quot;,&quot;Bird&quot;); print_r($a); ?> E.g: Array ( [a] => Dog [b] => Cat [0] => Horse [1] => Bird ) Output: Array Functions
  • 75. 02/21/12 array_rand( array,num ) function returns a random key from an array, or it returns an array of random keys if you specify that the function should return more than one key. Open Source Programming <?php $a=array(&quot;a&quot;=>&quot;Dog&quot;,&quot;b&quot;=>&quot;Cat&quot;,&quot;c&quot;=>&quot;Horse&quot;); print_r(array_rand($a,1)); ?> E.g: b Output: Array Functions
  • 76. 02/21/12 The array_reverse( array,preserve ) function returns an array in the reverse order. Open Source Programming <?php $a=array(&quot;a&quot;=>&quot;Dog&quot;,&quot;b&quot;=>&quot;Cat&quot;,&quot;c&quot;=>&quot;Horse&quot;); print_r(array_reverse($a)); ?> E.g: Array ( [c] => Horse [b] => Cat [a] => Dog ) Output: Array Functions
  • 77. 02/21/12 The array_search( value,array,strict ) function search an array for a value and returns the key. Open Source Programming <?php $a=array(&quot;a&quot;=>&quot;Dog&quot;,&quot;b&quot;=>&quot;Cat&quot;,&quot;c&quot;=>&quot;Horse&quot;); echo array_search(&quot;Dog&quot;,$a); ?> E.g: a Output: Array Functions
  • 78. 02/21/12 The array_slice( array, start, length, preserve ) function returns selected parts of an array. Open Source Programming <?php $a=array(0=>&quot;Dog&quot;,1=>&quot;Cat&quot;,2=>&quot;Horse&quot;,3=>&quot;Bird&quot;); print_r(array_slice($a,1,2)); ?> E.g: Array ( [0] => Cat [1] => Horse ) Output: Array Functions
  • 79. 02/21/12 The array_splice( array,start,length,array ) function removes selected elements from an array and replaces it with new elements. The function also returns an array with the removed elements. Open Source Programming <?php $a1=array(0=>&quot;Dog&quot;,1=>&quot;Cat&quot;,2=>&quot;Horse&quot;,3=>&quot;Bird&quot;); $a2=array(0=>&quot;Tiger&quot;,1=>&quot;Lion&quot;); array_splice($a1,0,2,$a2); print_r($a1); ?> E.g: Array ( [0] => Tiger [1] => Lion [2] => Horse [3] => Bird ) Output: Array Functions
  • 80. 02/21/12 The array_sum( array ) function returns the sum of all the values in the array. Open Source Programming <?php $a=array(0=>&quot;5&quot;,1=>&quot;15&quot;,2=>&quot;25&quot;); echo array_sum($a); ?> E.g: 45 Output: Array Functions
  • 81. 02/21/12 The arsort( array,sorttype ) function sorts an array by the values in reverse order. The values keep their original keys. Open Source Programming <?php $my_array = array(&quot;a&quot; => &quot;Dog&quot;, &quot;b&quot; => &quot;Cat&quot;, &quot;c&quot; => &quot;Horse&quot;); arsort($my_array); print_r($my_array); ?> E.g: Array ( [c] => Horse [a] => Dog [b] => Cat ) Output: Array Functions
  • 82. 02/21/12 The asort( array,sorttype ) function sorts an array by the values. The values keep their original keys Open Source Programming <?php $my_array = array(&quot;a&quot; => &quot;Dog&quot;, &quot;b&quot; => &quot;Cat&quot;, &quot;c&quot; => &quot;Horse&quot;); asort($my_array); print_r($my_array); ?> E.g: Array ( [b] => Cat [a] => Dog [c] => Horse ) Output: Array Functions
  • 83. 02/21/12 The krsort( array,sorttype ) function sorts an array by the keys in reverse order. The values keep their original keys. Open Source Programming <?php $my_array = array(&quot;a&quot; => &quot;Dog&quot;, &quot;b&quot; => &quot;Cat&quot;, &quot;c&quot; => &quot;Horse&quot;); krsort($my_array); print_r($my_array); ?> E.g: Array ( [c] => Horse [b] => Cat [a] => Dog ) Output: Array Functions
  • 84. 02/21/12 The ksort( array,sorttype ) function sorts an array by the keys. The values keep their original keys. Open Source Programming <?php $my_array = array(&quot;a&quot; => &quot;Dog&quot;, &quot;b&quot; => &quot;Cat&quot;, &quot;c&quot; => &quot;Horse&quot;); ksort($my_array); print_r($my_array); ?> E.g: Array ( [a] => Dog [b] => Cat [c] => Horse ) Output: Array Functions
  • 85. 02/21/12 The rsort( array ) function sorts an array by the values in reverse order. This function assigns new keys for the elements in the array. Existing keys will be removed. Open Source Programming <?php $my_array = array(&quot;a&quot; => &quot;Dog&quot;, &quot;b&quot; => &quot;Cat&quot;, &quot;c&quot; => &quot;Horse&quot;); rsort($my_array); print_r($my_array); ?> E.g: Array ( [0] => Horse [1] => Dog [2] => Cat ) Output: Array Functions
  • 86. 02/21/12 The sort( array ) function sorts an array by the values. This function assigns new keys for the elements in the array. Existing keys will be removed. Open Source Programming <?php $my_array = array(&quot;a&quot; => &quot;Dog&quot;, &quot;b&quot; => &quot;Cat&quot;, &quot;c&quot; => &quot;Horse&quot;); sort($my_array); print_r($my_array); ?> E.g: Array ( [0] => Cat [1] => Dog [2] => Horse ) Output: Array Functions
  • 87. 02/21/12 Open Source Programming CASE_LOWER CASE_UPPER SORT_ASC SORT_DESC SORT_REGULAR SORT_NUMERIC SORT_STRING SORT_LOCALE_STRING COUNT_NORMAL COUNT_RECURSIVE Array Constants EXTR_OVERWRITE EXTR_SKIP EXTR_PREFIX_SAME EXTR_PREFIX_ALL EXTR_PREFIX_INVALID EXTR_PREFIX_IF_EXISTS EXTR_IF_EXISTS EXTR_REFS
  • 88. 02/21/12 The count_chars( string,mode ) function returns how many times an ASCII character occurs within a string and returns the information. Open Source Programming String Functions Array ( [32] => 1 [33] => 1 [72] => 1 [87] => 1 [100] => 1 [101] => 1 [108] => 3 [111] => 2 [114] => 1 ) Output: <?php $str = &quot;Hello World!&quot;; print_r(count_chars($str,1)); ?> E.g:
  • 89. 02/21/12 The different return modes are: 0 - an array with the ASCII value as key and number of occurrences as value 1 - an array with the ASCII value as key and number of occurrences as value, only lists occurrences greater than zero 2 - an array with the ASCII value as key and number of occurrences as value, only lists occurrences equal to zero are listed 3 - a string with all the different characters used 4 - a string with all the unused characters Open Source Programming String Functions
  • 90. 02/21/12 The explode( separator, string, limit ) function breaks a string into an array. Open Source Programming Array ( [0] => Hello [1] => world. [2] => It's [3] => a [4] => beautiful [5] => day. ) Output: String Functions <?php $str = &quot;Hello world. It's a beautiful day.&quot;; print_r (explode(&quot; &quot;,$str)); ?> E.g:
  • 91. 02/21/12 The implode( separator,array ) & join ( separator,array ) function returns a string from the elements of an array. Open Source Programming Hello World! Beautiful Day! Output: String Functions <?php $arr = array('Hello','World!','Beautiful','Day!'); echo implode(&quot; &quot;,$arr); ?> E.g:
  • 92. 02/21/12 The ltrim( string,charlist ) & rtrim( string,charlist ) function will remove whitespaces or other predefined character from the left and right side of a string respectively. The soundex( string ) function calculates the soundex key of a string. The str_shuffle( string ) function randomly shuffles all the characters of a string. Open Source Programming String Functions
  • 93. 02/21/12 The strlen ( string ) function returns the length of a string. Open Source Programming Length = 12 Output: String Functions <?php $a= “hello World!”; echo “Length = “, strlen($a); ?> E.g:
  • 94. 02/21/12 The strrev ( string ) reverses the given string. Open Source Programming Reverse of “hello World!” is !dlroW olleh Output: String Functions <?php $a= “hello World!”; echo “Reverse of $a is “, strrev($a); ?> E.g:
  • 95. 02/21/12 The strtoupper ( string ) converts to upper case character The strtolower ( string ) converts to lower case character Open Source Programming Upper of “hello World!” is HELLO WORLD! Lower of “hello World!” is hello world Output: String Functions <?php $a= “hello World!”; echo “Upper of $a is “, strtoupper($a); echo “Lower of $a is “, strtolower($a); ?> E.g:
  • 96. 02/21/12 The strpos ( string,exp ) returns the numerical position of first appearance of exp. The strrpos ( string,exp ) returns the numerical position of last appearance of exp. Open Source Programming 2 9 Output: String Functions <?php $a= “hello World!”; echo strpos($a,”l”),”<br>”; echo strrpos($a,”l”); ?> E.g:
  • 97. 02/21/12 The substr ( string,start,length ) function returns a sub string of the size “length” from the position of “start”. Open Source Programming lo Output: String Functions <?php $a= “hello World!”; echo substr($a,3,2); ?> E.g:
  • 98. 02/21/12 The substr_count ( string,substr ) counts number of times a sub string occurred in given string. Open Source Programming 2 Output: String Functions <?php $a= “hello Worlod!”; echo substr_count($a,”lo”); ?> E.g:
  • 99. 02/21/12 The substr_replace ( string,replacement,start,len ) replaces a portion of a string with a replacement string, beginning the substitution at a specified starting position and ending at a predefined replacement length. Open Source Programming heaaorld! Output: String Functions <?php $a= “hello World!”; echo substr_replace($a,”aa”,2,5); ?> E.g:
  • 100. 02/21/12 The ucfirst ( string ) converts the first character to upper case. The ucwords ( string ) converts the first character of each word to upper case. Open Source Programming Hello world! Hello World! Output: String Functions <?php $a= “hello world!”; echo ucfirst($a),”<br>”; echo ucwords($a); ?> E.g:
  • 101. 02/21/12 The parse_str ( string,arr ) function parses a query string into variables. Open Source Programming 23 Kai Jim Output: String Functions <?php parse_str(&quot;id=23&name=Kai%20Jim&quot;); echo $id.&quot;<br />&quot;; echo $name; ?> E.g:
  • 102. 02/21/12 The str_replace( find,replace,string,count ) function replaces some characters with some other characters in a string. Note: str_ireplace() – for case sensitive Open Source Programming Array ( [0] => blue [1] => pink [2] => green [3] => yellow ) Replacements: 1 Output: String Functions <?php $arr = array(&quot;blue&quot;,&quot;red&quot;,&quot;green&quot;,&quot;yellow&quot;); print_r(str_ireplace(&quot;RED&quot;,&quot;pink&quot;,$arr,$i)); echo &quot;Replacements: $i&quot;; ?> E.g:
  • 103. 02/21/12 The str_pad( string,length,padchar,padtype ) function pads a string to a new length. Open Source Programming .........Hello World Output: String Functions <?php $str = &quot;Hello World&quot;; echo str_pad($str,20,&quot;.&quot;,STR_PAD_LEFT); ?> E.g:
  • 104. 02/21/12 The str_split( string,length ) function splits a string into an array. Default length is 1. Open Source Programming Array ( [0] => Hel [1] => lo ) Output: String Functions <?php print_r(str_split(&quot;Hello&quot;,3)); ?> E.g:
  • 105. 02/21/12 The str_word_count( string ) function counts the number of words in a string. Open Source Programming 2 Output: String Functions <?php echo str_word_count(&quot;Hello world!&quot;); ?> E.g:
  • 106. 02/21/12 The strcasecmp( string1,string2 ) function compares two strings as case insensitive. Strcmp( string1,string2 ) compares as case sensitive. This function returns: 0 - if the two strings are equal < 0 - if string1 is less than string2 > 0 - if string1 is greater than string2 Open Source Programming 0 1 Output: String Functions <?php echo strcasecmp(&quot;Hello world!&quot;,&quot;HELLO WORLD!&quot;); echo “<br>”; echo strcmp(&quot;Hello world!&quot;,&quot;HELLO WORLD!&quot;); ?> E.g:
  • 107. 02/21/12 The stripos( string,find,start ) function returns the position of the first occurrence of a string inside another string. But doesn’t check for case sensitivity. In strpos it’s d same but check for case sensitivity. Strpos( string,find,start ) – case sensitive. If the string is not found, this function returns FALSE. Open Source Programming 6 Output: String Functions <?php echo stripos(&quot;Hello world!&quot;,&quot;WO&quot;); ?> E.g:
  • 108. 02/21/12 The stristr( string,exp ) function searches for the first occurrence of a string inside another string. This function returns the rest of the string (from the matching point), or FALSE, if the string to search for is not found Open Source Programming World! Have a nice day Output: String Functions <?php echo stristr(&quot;Hello world! Have a nice day&quot;,&quot;WORLD&quot;); ?> E.g:
  • 109. 02/21/12 Boolean Checkdate( day,month,year ) – used to check the given parameters are a valid date. Date( formatstring ) - The date() function returns a string representation of the current date and/or time formatted according to the instructions specified by a predefined format. Array Getdate ( int timestamp ) – returns array of datetime components Time() – returns time stamp Mktime( int h,int min, int sec, int day, int mnth, int yr ) – create a date and time Open Source Programming Date Functions
  • 110.
  • 111.
  • 112. 02/21/12 $_SERVER: The $_SERVER super global contains information created by the Web server and offers a bevy of information regarding the server and client configuration and the current request environment. $_GET & $_POST: The $_GET and $_POST super globals are used to retrieve information from forms, like user input. $_COOKIE: The $_COOKIE super global stores information passed into the script through HTTP cookies Open Source Programming Super Globals
  • 113. 02/21/12 $_ENV: The $_ENV super global offers information regarding the PHP parser’s underlying server environment. $_SESSION: The $_SESSION super global contains information regarding all session variables $_FILES: The $_FILES super global contains information regarding data uploaded to the server via the POST method. This super global is a tad different from the others. Open Source Programming Super Globals
  • 114.
  • 115. 02/21/12 Function E.g . <?php function generateFooter() { echo &quot;Copyright 2007 W. Jason Gilmore&quot;; } // Once defined, call the function likes so: generateFooter(); // function calling ?> Output: Copyright 2007 W. Jason Gilmore Open Source Programming User Defined Functions
  • 116.
  • 117. 02/21/12 Function with argument: <?php function writeName ($fname ) { echo $fname . &quot; Refsnes.<br />&quot;; } echo &quot;My name is &quot;; writeName(&quot; Kai Jim &quot;); echo &quot;My sister's name is &quot;; writeName(&quot; Hege &quot;); echo &quot;My brother's name is &quot;; writeName(&quot; Stale &quot;); ?> Open Source Programming Output: My name is Kai Jim Refsnes. My sister's name is Hege Refsnes. My brother's name is Stale Refsnes. User Defined Functions Formal Argument Fn. Call with Actual Argument
  • 118. 02/21/12 Function with arguments & return value: <?php function calculateAmt ($cost, $num ) { return ($cost * $num); } $price=10; $tot=5; Echo “ Total Amount “, calculateAmt($price, $tot); ?> Open Source Programming Output: Total Amount 50 User Defined Functions
  • 119. 02/21/12 Fn. Call by Ref.: <?php $cost = 20.99; $tax = 0.0575; function calculateCost( & $cost, $tax) { // Modify the $cost variable $cost = $cost + ($cost * $tax); // Perform some random change to the $tax variable. $tax += 4; } Echo “(bfr fn call) Cost is $cost <br>”; calculateCost($cost, $tax); Echo &quot;Tax is $tax*100 <br>&quot;; Echo “(aft fn call) Cost is: $cost”; ?> Open Source Programming Output: (bfr fn call) Cost is 20.99 Tax is 5.75 (aft fn call) Cost is: 22.20 User Defined Functions
  • 120.
  • 121.
  • 122. 02/21/12 Open Source Programming PHP Form Handling < form method = POST action = form.php> Name: < input type =text name = fname > <br > Age: < input type = text name = age > < br > < input type = submit value = submit> </ form > HTML Code (Form.html) <?php $a = $_POST[' fname ']; $b = $_POST[' age ']; echo &quot;Welcome Mr./Ms. $a. You are $b years old &quot;; ?> PHP Code (form.php)
  • 123. 02/21/12 Open Source Programming HTML Browser Result PHP Form Handling
  • 124. 02/21/12 Open Source Programming Open Source Programming 1. The application attempts something. 2. If the attempt fails, the exception-handling feature throws an exception. 3. The assigned handler catches the exception and performs any necessary tasks. 4 . The exception-handling feature cleans up any resources consumed during the attempt. In PHP, Exception handling can be done by try …throw… catch . Exception Handling PHP
  • 125. 02/21/12 Open Source Programming Open Source Programming Exception handling syntax: Try { statement block; if goes wrong throw new exception(error message) } catch (exception $E) { echo $E.getMessage(); } Exception Handling PHP
  • 126. 02/21/12 <?php $a=10; $b=0; try { if ($b == 0) throw new exception(&quot;Divide by zero error&quot;); $c = $a/$b; echo &quot; $a&quot;,&quot; / &quot;,&quot;$b = &quot;, $a/$b; } catch(Exception $e) { echo $e->getMessage(); } ?> Open Source Programming Output: Divide by zero error Exception Handling in PHP
  • 127.
  • 128.
  • 129.
  • 130. 02/21/12 <?php class ExtendClass extends SimpleClass {     // Redefine the parent method     function displayVar()     {         echo &quot;Extending class&quot;;         parent::displayVar();     } } $extended = new ExtendClass(); $extended->displayVar(); ?> Open Source Programming Extending class Hello E.G . Output: Inheritance
  • 131.
  • 132. 02/21/12 E.g . <?php class BaseClass {    function __construct() {        print &quot;In BaseClass constructor&quot;;    } } class SubClass extends BaseClass {    function __construct() {        parent::__construct();        print &quot;In SubClass constructor&quot;;    } } $obj = new BaseClass(); $obj = new SubClass(); ?> Output: In BaseClass constructor In BaseClass constructor In SubClass constructor Open Source Programming Constructors & Destructors
  • 133.
  • 134. 02/21/12 E.g. <?php class foo { public function printItem($string) { echo 'Foo: ' . $string . PHP_EOL; } public function printPHP() { echo 'PHP is great.' . PHP_EOL; } } class c extends foo { public function printItem($string) { echo &quot;Extending from FOO&quot;; parent::printItem(&quot;this is gud&quot;); } } $foo = new foo(); $c = new c(); $foo->printItem('baz'); ' $foo->printPHP(); $c->printItem('from C'); $c->printPHP(); ?> Foo: baz PHP is great. Extending from FOO Foo: this is gud PHP is great. Output: Open Source Programming Overloading
  • 135. 02/21/12 Open Source Programming Can insert the content of one PHP file into another PHP file before the server executes it, with the include() or require() function. The include() function takes all the content in a specified file and includes it in the current file. Files are included based on the file path given . The two functions are identical in every way, except how they handle errors: 1. include() generates a warning, but the script will continue execution 2. require() generates a fatal error, and the script will stop E.g. <?php include(&quot;wrongFile.php&quot;); echo &quot;Hello World!&quot;; ?> Output: Error Message Hello World Include & Require
  • 136. 02/21/12 Open Source Programming E.g. <?php require(&quot;wrongFile.php&quot;); echo &quot;Hello World!&quot;; ?> Output: Error Message Include & Require
  • 137.
  • 138.
  • 139. 02/21/12 File closing can be done by fclose(fp); E.g. <?php $ourFileName = &quot;testFile.txt&quot;; $ourFileHandle = fopen($ourFileName, ‘w') or die(&quot;can't open file&quot;); fclose($ourFileHandle); ?> Files
  • 140. 02/21/12 Open Source Programming 1) fopen(filename,mode) - used for opening a file with specific mode. 2) fclose(fp) - used to close the file. (fp -> filepointer) 3) feof(fp) - used to find the End of File 4) fgetc(fp) - Gets character from file pointer 5) fgets(fp) - Gets a line from file pointer 6) fread(fp,size) - Binary-safe file read 7) fscanf(fp,format) - Parses input from a file according to a format 8) fwrite(fp,string) - Binary-safe file write 9) file_put_contents(fp,string) - Write a string to a file 10) file_get_contents(fp) - Reads entire file into a string 11) file(fp) - Reads entire file into an array 12) file_exists(fp) - Checks whether a file or directory exists Some File Functions
  • 141. 02/21/12 Open Source Programming 13) is_readable(fp) - Tells whether the filename is readable 14) is_writable(fp) - Tells whether the filename is writable 15) is_file(path) - Tells whether the filename is a regular file 16) is_dir(path) - Tells whether the filename is a directory 17) is_link(path) - Tells whether the filename is a symbolic link 18) readlink(path) - Returns the target of a symbolic link 19) readdir - Read entry from directory handle 20) glob - Find pathnames matching a pattern 21) filesize(fp) - Gets file size 22) filetype(fp) - Gets file type 23) fprintf(fp,format) - Write a formatted string to a stream 24) fstat(fp) - Gets information about a file using an open file pointer Some File Functions
  • 142. 02/21/12 Open Source Programming <?php $myFile = &quot;testFile.txt&quot;; $fh = fopen($myFile, 'w') or die(&quot;can't open file&quot;); $stringData = &quot;Bobby Bopper&quot;; fwrite($fh, $stringData); $stringData = &quot;Tracy Tanner&quot;; fwrite($fh,$stringData); fclose($fh); ?> E.g. <?php $ourFileName = &quot;testFile.txt&quot;; $ourFileHandle = fopen($ourFileName, ‘w') or die(&quot;can't open file&quot;); ?> File Write
  • 143. 02/21/12 Open Source Programming E.g. <?php // get contents of a file into a string $filename = &quot;testfile.txt&quot;; $handle = fopen($filename, &quot;r&quot;); //$contents = fread($handle, filesize($filename)); while (!feof($handle)) echo fgetc($handle),&quot;<br>&quot;; //print_r(&quot;$contents&quot;); fclose($handle); ?> Output: Bobby Bopper Tracy Tanner File Read
  • 144. 02/21/12 Open Source Programming E.g. <?php $myFile = &quot;testFile.txt&quot;; $fh = fopen($myFile, 'a+') or die(&quot;can't open file&quot;); $stringData = &quot;new1&quot;; fwrite($fh, $stringData); $stringData = &quot;new2&quot;; fwrite($fh, $stringData); fclose($fh); ?> Output: Bobby Bopper Tracy Tannernew1new2 File Append

Editor's Notes

  1. Outputs
  2. Statements
  3. Up to 14-01-11 D batch
  4. 17-01-11 DBatch stop