www.ardentcollaborations.

com

Ardent Collaborations

LAMP refers to a solution stack of software, usually free and open source software, used to run dynamic Web sites or servers. The original expansion is as follows: Linux - operating system; Apache - the Web server; MySQL - the database management system PHP - what is PHP?

Ardent Collaborations

PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML. <body>  <?php phpinfo();          ?> </body> the code is executed on the server, generating HTML which is then sent to the client. The client would receive the results of running that script, but would not know what the underlying code was.

You need three things to make this work.There are three main areas where PHP scripts are used.  Writing desktop applications. This is the most traditional and main target field for PHP. but if you know PHP very well. You only need the PHP parser to use it this way. The PHP parser. and would like to use some advanced PHP features in your client-side applications you can also use PHP-GTK to write such programs. PHP is probably not the very best language to create a desktop application with a graphical user interface. .  Server-side scripting. You can make a PHP script to run it without any server or browser. a web server and a web browser.  Command line scripting.

PDF files and even Flash movies (using libswf and Ming) generated on the fly. PHP has also support for most of the web servers today. or a mixture of them. . you also have the choice of using procedural programming or object oriented programming. One of the strongest and most significant features in PHP is its support for a wide range of databases. PHP's abilities includes outputting images. With PHP you are not limited to output HTML.     PHP can be used on all major operating systems.

Andi Gutmans and Zeev Suraski. who wrote the original Common Gateway Interface binaries.Rasmus Lerdorf. who rewrote the parser that formed PHP 3 And developed the famous Zend Engine. Ardent Collaborations .

It began in 1994 as a set of Common Gateway Interface binaries written in the C programming language by the Rasmus Lerdorf. Ardent Collaborations .PHP originally stood for Personal Home Page. He created these Personal Home Page Tools to maintain his personal homepage.

and less consistent. Ardent Collaborations .Lerdorf released PHP publicly on June 8. 1995 named PHP version 2 The syntax was similar to Perl but was more limited. simpler.

Zeev Suraski and Andi Gutmans. The development team officially released PHP/FI 2 in November 1997. The official launch of PHP 3 came in June 1998 Ardent Collaborations . two Israeli developers at the Technion IIT. rewrote the parser in 1997 and formed the base of PHP 3 They changed the name to Hypertext Preprocessor.

was released. powered by the new Zend Engine II. powered by the Zend Engine 1. PHP 4.Suraski and Gutmans then started a new rewrite of PHP's core. In 2008. PHP 5 became the only stable version under development. producing the Zend Engine in 1999.0. PHP 5 was released. On July 13.0 will be launched very soon. 2004. Ardent Collaborations . On May 22. PHP 6. 2000.

The Zend Engine is an open source scripting engine (a Virtual Machine). commonly known for the important role it plays in the web automation language PHP. Ardent Collaborations .

short_open_tag is set to "On" in php. asp_tags is set to "On" Ardent Collaborations .• • To activate recognition for short tags.2.6\bin\php.ini) To activate recognition for the ASP style tags.ini (C:\wamp\bin\apache\apache2.

or double) string Two compound types:  array  object And finally two special types:  resource  NULL .PHP supports eight primitive types. Four scalar types:     boolean integer float (floating-point number.

and the string "0"  an array with zero elements  an object with zero member variables (PHP 4 only)  the special type NULL ◦ Every other value is considered TRUE .This is the simplest type. A boolean expresses a truth value.0 (zero)  the empty string. It can be either TRUE or FALSE (case insensitive) the following values are considered FALSE:  the boolean FALSE itself  the integer 0 (zero)  the float 0.

2. ... 1. // a negative number $a = 0123. 0. <?php $a = 1234.. the rest of the number is ignored.. . 8 or 9). // octal number (equivalent to 8 3 decimal) $a = 0x1A.e. -1.  An integer is a number of the set Z = {. // hexadecimal number (equival ent to 26 decimal) ?> ◦ If an invalid digit is given in an octal integer (i.}. // decimal number $a = -123. -2..

234. or "real numbers") can be specified using any of the following syntaxes: <?php $a = 1.2e3.  Floating point numbers (also known as "floats". ?> .  $c = 7E-10. "doubles".  $b = 1.

. but no parsing is done inside a nowdoc. Note: A nowdoc is specified similarly to a heredoc. A string literal can be specified in four different ways: ◦ single quoted ‘aaa’ ◦ double quoted “aaa” ◦ heredoc syntax ◦ nowdoc syntax  <<<'EOT'  $str = <<<HDS Example of string HDS.A string is series of characters.

it has been unset(). it has not been set to any value yet.  A resource is a special variable. A variable is considered to be null if: it has been assigned the constant NULL. database connections etc. NULL is the only possible value of type NULL. holding a reference to an external resource. The special NULL value represents a variable with no value. resource variables hold special handlers to opened files.      .

(boolean) .cast to integer  (bool).cast to string  (array) . (integer) . (real) .cast to NULL (PHP 5) .cast to float  (string) .cast to object  (unset) . The casts allowed are:  (int). (double).Type casting in PHP works much as it does in C: the name of the desired type is written in parentheses before the variable which is to be cast.cast to boolean  (float).cast to array  (object) .

That is. <?php $a = 'hello'. ?> . echo "<br>$a $hello". $$a = 'world'. Sometimes it is convenient to be able to have variable variable names. a variable name which can be set and used dynamically. echo "$a ${$a}".

gettype( $undecided ).Changing Type with settype() Knowing Type with gettype() <? $testing = 5.14 settype( $undecided. print gettype( $testing ). // integer print "<br>". // double print " -. print "<br>". $testing = "five". // string ?> <? $undecided = 3. // string settype( $undecided.$undecided<br>". print gettype( $testing ).14. print gettype( $undecided ). print gettype( $undecided ). // 1 ?> Ardent Collaborations . string ). // 3.$undecided<br>". boolean ). // boolean print " -.

Note: There is $ in constant.USER. you want to work with a value that you do not want to alter throughout your script's execution. "Gerald" ). you can define a constant. print "Welcome ". e. You can change their values and the type of data they store at any time. define ( "USER". If. 42 ). Ardent Collaborations .• – define( "CONSTANT_NAME". however. Variables offer a flexible way of storing data.g.

} bighello(). $argument2 ) { // function code here } <?php function bighello() { print "<h1>HELLO!</h1>". ?> Ardent Collaborations .function some_function( $argument1.

• • • <?php $life = 420. Ardent Collaborations . } meaningOfLife(). Accessing Global Variables with the global Statement. print "The meaning of life is $life<br>". function meaningOfLife() { global $life. ?> A Variable Declared Within a Function Is Unavailable Outside the Function Variables Defined Outside Functions Are Inaccessible from Within a Function by Default.

function andAnotherThing( $txt ) { global $num_of_calls. $num_of_calls++. print("We build a fine range of widgets<p>"). ?> Ardent Collaborations . print "<h1>$num_of_calls.<?php $num_of_calls = 0. print("Finest in the world<p>"). $txt</h1>". print "<h1>$num_of_calls. ?> <?php function andAnotherThing( $txt ) { static $num_of_calls = 0. andAnotherThing("Doodads"). andAnotherThing("Doodads"). $num_of_calls++. } andAnotherThing("Widgets"). print("We build a fine range of widgets<p>"). } andAnotherThing("Widgets"). print("Finest in the world<p>"). $txt</h1>".

3) // 13 Floor(12.3) //12 include(“url") require(“url”) Ardent Collaborations . Max() Min() Abs(-100) round(13. echo() – may be used as a function.• • • • • • • • • • print ().64) //14 Rand() //create random number Ceil(12.

The two constructs are identical in every way except how they handle failure. They both produce a Warning. but require() results in a Fatal Error. .

array elements are indexed by number starting at zero Ardent Collaborations . By default. An index to an array element can be either a number or a string. and access many values under one name. It enables you to store. order. Each item in an array is commonly referred to as an element. That is. a variable that contains multiple elements indexed by numbers or strings. Each element can be accessed directly via its index.• • • An array is a list variable.

print "$users[2]". "Ritesh" ). $users[ ] = " Sharon". "Rohan".1. 1. print "$users[2]". "Rohit". $users[ ] = " Betty". Ardent Collaborations . $users[ ] = " Harry". Defining or Adding to Arrays with the Array Identifier $users[ ] = " Bert". Defining Arrays with the array() Function $users = array ("Raja".

print $character[age].age=>30). Ardent Collaborations .occupation=>"superhero". 1. Directly Defining or Adding to an Associative Array $character[name] = "bob". $character[occupation] = "superhero". Defining Associative Arrays with the array() Function $character = array (name=>"bob". $character[age] = 30. 1.Arrays indexed by strings are known as associative arrays. print $character[occupation].

age=>24. occupation=>"superhero". age=>63. <?php $characters = array ( array ( name=>"bob". occupation=>"arch villain". specialty=>"nanotechnology" ) ). specialty=>"x-ray vision" ). array ( name=>"sally". occupation=>"superhero".Arrays that contain arrays as their elements are known as multidimensional arrays. specialty=>"superhuman strength" ). array ( name=>"mary". age=>30. print $characters[0][occupation]. // prints "superhero" ?> Ardent Collaborations .

"Sharon". $users = array ("Bert". "Harry" ).• We can access an element of an array by using its index: • print $user[4] count() returns the number of elements in an array. • Ardent Collaborations . "Betty". print $users[count($users)− 1].

.. foreach ( $users as $val ) { print "$val<br>". "Sharon".Syntax: foreach( $array as $temp ){ //. } • Ardent Collaborations . } • Example: $users = array ("Bert". "Harry" ). "Betty".

age=>30).. } • Example: $character = array (name=>"bob". } Ardent Collaborations .• Syntax: foreach( $array as $key=>$value ){ //. foreach ( $character as $key=>$val ) { print "$key = $val<br>"..occupation=>"superhero".

foreach ( $third as $val ){ print "$val<BR>".• Joining Two Arrays with array_merge() $first = array("a". print "There are $total elements in \$first<P>". 3 ). foreach ( $first as $val ){ print "$val<BR>". "b". "c"). "b". $second ). Ardent Collaborations . 2. } – accepts two or more arrays and returns a merged array combining all their elements. • Adding Multiple Variables to an Array with array_push() $first = array("a". "c"). $third = array_merge( $first. $second = array(1.3). } – accepts an array and any number of further parameters and returns the total number of elements in the array it transforms.2. $total = array_push( $first. 1.

} – removes and returns the first element of an array • Slicing Arrays with array_slice() $first = array("a". print "there are ". 2. Ardent Collaborations . "d". } – accepts an array as an argument.• Removing the First Element of an Array with array_shift() $an_array = array("a"." elements in \$an_array <br>". a starting position (offset). 3). "c". "e". "b". $second = array_slice($first.count($an_array). "c"). foreach ( $second as $var ){ print "$var<br>". "b". "f"). print "$val<BR>". and an (optional) length and returns a new array. while ( count( $an_array) ) { $val = array_shift( $an_array).

"c")."f". } • Sorting an Associative Array by Key with ksort() – ksort( $first )."a". Ardent Collaborations . foreach ( $an_array as $var ){ print "$var<BR>". foreach ( $first as $key => $val ){ print "$key = $val<BR>".• Sorting Numerically Indexed Arrays with sort() $an_array = array("x"."second"=>2. sort( $an_array). asort( $first ). } • Sorting an Associative Array by Value with asort() $first = array("first"=>5."third"=>1).

Server and Environment variables. Cookie. } • Ardent Collaborations .When PHP processes a page. POST. it checks for GET. • It creates an array called $GLOBALS foreach ( $GLOBALS as $key=>$value ){ print "$key == $value<br>". this information is collectively known as EGPCS.

$HTTP_SERVER_VARS or $_SERVER 5. $HTTP_POST_VARS or $_POST 3. $HTTP_GET_VARS or $_GET 2.PHP creates 5 global arrays: 1. $HTTP_ENV_VARS or $_ENV Ardent Collaborations . $HTTP_COOKIE_VARS or $_COOKIE 4.

header() is used to send a raw HTTP header. Syntax: void header ( string $string [. Response is sent by the server to the client. $_POST etc. int $http_response_code ]] ) Ardent Collaborations . we have global arrays like $_GET. bool $replace= true [.For fetching request data.

example. ◦ "Location:“  returns a REDIRECT (302) status code to the browser. There are two special-case header calls ◦ "HTTP/“  used to figure out the HTTP status code to send.  header("Location: http://www. ◦ Can be used in some other ways also. .0 404 Not Found").  header("HTTP/1.com/").

pdf"').pdf header('ContentDisposition: attachment. filename="downloaded. // The PDF source is in original.pdf'). // It will be called downloaded.  An example: <?php // We'll be outputting a PDF header('Content-type: application/pdf').pdf readfile('original. ?> .

◦ header("Content-Disposition: attachment.doc"). . Word: ◦ header("Content-type: application/msword").Filename=document_name.xls").  Excel: ◦ header("Content-type: application/vnd. ◦ header("Content-Disposition: attachment.ms-excel").Filename=document_name.

ini file to create pdf in runtime. ◦ An example:  Click here .dll ◦ Add this line in the php. extension=php_pdf.

$database = “ardent". $password) OR die ('Could not connect to MySQL: ' .$server = "localhost". $username. @mysql_select_db ($database) OR die ('Could not select the database: ' . $password = "". mysql_error() ). $username = "root". @mysql_connect ($server. Ardent Collaborations . mysql_error() ).

} else { echo "Sorry. } Ardent Collaborations .'Kolkata')" . There is a temporary problem.".//connect $sql = "INSERT INTO std VALUES(1. mysql_error(). if($results) { echo "Added".'Rohit'. Try again. $results = mysql_query ( $sql).

$sql = "SELECT * from std". echo "$row[name] ". while ($row = mysql_fetch_array($result)) { echo "$row[roll]". echo "$row[addr] ". $result = mysql_query($sql). } Ardent Collaborations .

include_once() and require_once() includes the file only once. Ardent Collaborations .  Include() and require() function enables us to incorporate files into your PHP documents.

   Checking for Existence with file_exists() is_file() for checking it is a file or not. is_dir() for checking it is a directory or not. Other Functions: ◦ is_readable() ◦ is_writable ◦ is_executable Ardent Collaborations  .

print date("D d M Y g:i A".  Determining File Size with filesize() last accessed time with fileatime().txt was last accessed on ". print "test. $atime = fileatime( "test. $atime).txt" ).  the modification date of a file with the function filemtime() Ardent Collaborations . e.g.

g. e.g. Ardent Collaborations . the contents are not disturbed. unlink("myfile. but the modification date is updated to the time at which the function executed.txt"). e. unlink() :remove an existing file.txt"). touch("myfile.touch( ) : create a file If the file already exists.

for appending : $fp = fopen( "test. write ('w'). 'a' ). and append ('a'). 'r' ).txt". Ardent Collaborations . for writing: $fp = fopen( "test. followed by a string containing the mode in which the file is to be opened.fopen() fopen() requires a string containing the file path.txt". read ('r'). Modes: for reading: $fp = fopen( "test.txt". 'w' ).

}  Ardent Collaborations . no of bytes)  Reading Arbitrary Amounts of Data from a File with fread()  feof(file pointer) tells the end of file while ( ! feof( $fp ) ) { $line = fgets( $fp.Line by Line: fgets(file pointer. 1024 ). print "$line<br>".

change the current  Ardent Collaborations . fgetc(file pointer) reads a character fseek(file pointer. int offset) position within a file.

$fp  $fp ◦ ◦ Both of  = fopen( "test. "w" ) = fopen( "test.txt". Ardent Collaborations . "a" ) fwrite() fputs() them accepts a file pointer and a string.txt".

1970.The integer returned by time() represents the number of seconds elapsed since midnight GMT on January 1. This moment is known as the UNIX epoch. Ardent Collaborations . and the number of seconds that have elapsed since then is referred to as a time stamp.

Getdate() returns an associative array Ardent Collaborations .

// no argument passed so today's date will be used print_r($date_array). ?> Ardent Collaborations .<?php $date_array = getdate(time()+330*60). print "<hr>Today's date: $date_array[mday]/ $date_array[mon]/ $date_array[year]<p>".

Date() returns string Ardent Collaborations .

mktime() accepts up to six integer arguments in the following order:  hour  minute  second  month  day of month  year Ardent Collaborations .returns a time stamp that you can then use with date() or getdate().

and year.Checkdate() accepts three integers: month. checkdate() returns true if the date is valid. day. Ardent Collaborations .

com".com\r\nReplyTo: st@ardentcollaborations. $subject.$to =email id $subject = subject of the mail $message = body of the mail $headers = "From: st@ardentcollaborations. $headers ) Ardent Collaborations . It returns true. if mail sent successfully. $message. @mail( $to.

php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> Choose a file to upload: <input name="uploadedfile" type="file" /><br /> <input type="submit" value="Upload File" /> </form> For binary data enctype must be multipart/formdata Ardent Collaborations .<form enctype="multipart/form-data" action="uploader.

Ardent Collaborations . If the file is not moved to a different location it will be destroyed! To save our precious file we are going to need to make use of the $_FILES associative array.the uploaded file exists in a temporary storage area on the server.

It has two parameter, first s the form's input name and the second index can be either "name", "type", "size", "tmp_name" or "error". Like this: $_FILES["file"]["name"] - the name of the uploaded file $_FILES["file"]["type"] - the type of the uploaded file $_FILES["file"]["size"] - the size in bytes of the uploaded file $_FILES["file"]["tmp_name"] - the name of the temporary copy of the file stored on the server $_FILES["file"]["error"] - the error code resulting from the file upload
Ardent Collaborations

move_uploaded_file($_FILES['uploadedfile'] ['tmp_name'], $target_path)

$target_path is the location where to save the file

Ardent Collaborations

$target_path = "uploads/"; $target_path = $target_path . $_FILES['uploadedfile'] ['name']; if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) echo "<br>The file ". $_FILES['uploadedfile']['name']. " has been uploaded"; else echo "<br>There was an error uploading the file, please try again!";

Ardent Collaborations

Print a string using  print  echo  printf Ardent Collaborations .

Ardent Collaborations .

255).<?php $r=rand(0.$r.255). $g=rand(0.$b). ?> <body bgcolor=<?php printf("#%x%x%x".255). $g. $b=rand(0. ?> > Ardent Collaborations .

string convert_uudecode ( string $data ): decodes a uuencoded string Ardent Collaborations .   chr() Return a specific character by ASCII string convert_uuencode ( string $data ): encodes a string using the uuencode algorithm.

if (crypt($user_input. $password) == $password) { echo "Password verified!". . <?php $password = crypt('mypassword'). } ?> Ardent Collaborations crypt — One-way string encryption (hashing): return an encrypted string using the standard Unix DES-based encryption algorithm.

hash — Generate a hash value (message digest): it takes 2 args ( string $algo . string $data). Ardent Collaborations .md5() — Calculate the md5 hash of a string: Calculates the MD5 hash of str using the RSA Data Security sha1 — Calculate the sha1 hash of a string: Calculates the sha1 hash of str using the US Secure Hash Algorithm 1.

$comma_separated = join(". 'Kolkata').Sharma.". // Rohit. echo $comma_separated. $array = array('Rohit'.Join array elements with a glue string. $array).Kolkata Ardent Collaborations . 'Sharma'.

$str). Ardent Collaborations ." . print_r($ar).Sharma.Returns an array of strings.Kolkata". each of which is a substring of string formed by splitting it on boundaries formed by the string delimiter . $str = "Rohit. $ar=explode(".

Strip whitespace (or other characters) from the end of a string Ardent Collaborations .   trim() .Strip whitespace (or other characters) from the beginning and end of a string ltrim() .Strip whitespace (or other characters) from the beginning of a string rtrim() .

 str_replace ( $search . $replace .  str_replace: Replace all occurrences of the search string with the replacement string str_ireplace — Case-insensitive version of str_replace(). $subject) Ardent Collaborations .

the input is padded with spaces. int $pad_type= STR_PAD_RIGHT ]] ) This functions returns the input string padded on the left. or both sides to the specified padding length. Ardent Collaborations . If pad_type is not specified it is assumed to be STR_PAD_RIGHT. otherwise it is padded with characters from pad_string up to the limit.Pad a string to a certain length with another string string str_pad ( string $input . int $pad_length [. Optional argument pad_type can be STR_PAD_RIGHT. If the optional argument pad_string is not supplied. or STR_PAD_BOTH. STR_PAD_LEFT. string $pad_string= " " [. the right.

10). <?php echo str_repeat("-=".string str_repeat ( string $input . int $multiplier ) Returns input repeated multiplier times. ?> Ardent Collaborations .

Sign up to vote on this title
UsefulNot useful