_tnd_147b6c446d0f9c0d6f9a6bc786500862dce26509

Upload: chandangupta86

Post on 09-Apr-2018

223 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    1/79

    Ardent Collaborations

    www.ardentcollaborations.com

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    2/79

    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 originalexpansion is as follows:Linux - operating system;Apache - the Web server;MySQL - the database management systemPHP - what is PHP?

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    3/79

    PHP is a widely-used general-purpose scriptinglanguage that is especially suited for Webdevelopment and can be embedded into HTML.

    the code is executed on the server, generating

    HTML which is then sent to the client. The clientwould receive the results of running that script, butwould not know what the underlying code was.

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    4/79

    There are three main areas where PHP scripts areused.

    Server-side scripting. This is the most traditionaland main target field for PHP. You need three thingsto make this work. The PHP parser, a web serverand a web browser.

    Command line scripting. You can make a PHP scriptto run it without any server or browser. You onlyneed the PHP parser to use it this way.

    Writing desktop applications. PHP is probably notthe very best language to create a desktopapplication with a graphical user interface, but ifyou know PHP very well, and would like to use someadvanced PHP features in your client-sideapplications you can also use PHP-GTK to write

    such programs.

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    5/79

    PHP can be used on all major operating systems. PHP has also support for most of the web servers

    today. you also have the choice of using procedural

    programming or object oriented programming, or amixture of them. With PHP you are not limited to output HTML. PHP's

    abilities includes outputting images, PDF files andeven Flash movies (using libswf and Ming)

    generated on the fly. One of the strongest and most significant features

    in PHP is its support for a wide range of databases.

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    6/79

    Ardent Collaborations

    Rasmus Lerdorf, who wrote the original Common Gateway Interface binaries,

    Andi Gutmans and Zeev Suraski, who rewrote the parser that formed PHP 3And developed the famous Zend Engine.

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    7/79Ardent Collaborations

    PHP originally stood for Personal Home Page.

    It began in 1994 as a set ofCommon GatewayInterface binaries written in the C programminglanguage by the Rasmus Lerdorf.He created these Personal Home Page Tools to

    maintain his personal homepage.

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    8/79Ardent Collaborations

    Lerdorf released PHP publicly onJune 8, 1995named PHP version 2The syntax was similar to Perl but was morelimited, simpler, and less consistent.

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    9/79Ardent Collaborations

    Zeev Suraski and Andi Gutmans, two Israelidevelopers at the Technion IIT, rewrote the

    parser in 1997 and formed the base of PHP 3They changed the name to HypertextPreprocessor.The development team officially released PHP/FI

    2 in November 1997.The official launch of PHP 3 came in June 1998

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    10/79Ardent Collaborations

    Suraski and Gutmans then started a new rewriteof PHP's core, producing the Zend Engine in1999.

    On May 22, 2000, PHP 4, powered by the ZendEngine 1.0, was released.OnJuly 13, 2004, PHP 5 was released, poweredby the new Zend Engine II.In 2008, PHP 5 became the only stable versionunder development.PHP 6.0 will be launched very soon.

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    11/79Ardent Collaborations

    The Zend Engine is an open source scriptingengine (a Virtual Machine), commonly known forthe important role it plays in the web automationlanguage PHP.

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    12/79

    To activate recognition for short tags, short_open_tag is setto "On" in php.ini(C:\wamp\bin\apache\apache2.2.6\bin\php.ini)

    To activate recognition for the ASP style tags, asp_tags is setto "On"

    Ardent Collaborations

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    13/79

    PHP supports eight primitive types.Four scalar types:

    boolean integer

    float (floating-point number, or double) string

    Two compound types: array object

    And finally two special types: resource NULL

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    14/79

    This is the simplest type. A boolean expresses atruth value. It can be either TRUE or FALSE (caseinsensitive)

    the following values are considered FALSE: the boolean FALSE itself the integer 0 (zero) the float 0.0 (zero) the empty string, 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

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    15/79

    An integer is a number of the set Z = {...,-2, -1, 0, 1, 2, ...}.

    If an invalid digit is given in an octalinteger(i.e.8 or 9), the rest of the number is ignored.

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    16/79

    Floating point numbers (also known as"floats", "doubles", or "real numbers") can bespecified using any of the following syntaxes:

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    17/79

    A string is series of characters.A string literal can be specified in four different

    ways: single quoted aaa double quoted aaa

    heredoc syntax $str =

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    18/79

    A resource is a special variable, holding a referenceto an external resource.

    resource variables hold special handlers to openedfiles, database connections etc.

    The special NULL value represents a variable withno value. NULL is the only possible value of typeNULL.

    A variable is considered to be null if: it has been assigned the constant NULL. it has not been set to any value yet. it has been unset().

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    19/79

    Type casting in PHP works much as it does in C: thename of the desired type is written in parenthesesbefore the variable which is to be cast.

    The casts allowed are:

    (int), (integer) - cast to integer (bool), (boolean) - cast to boolean (float), (double), (real) - cast to float (string) - cast to string (array) - cast to array (object) - cast to object (unset) - cast to NULL (PHP 5)

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    20/79

    Sometimes it is convenient to be able tohave variable variable names. That is, avariable name which can be set and useddynamically.

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    21/79

    Ardent Collaborations

    Changing Type with settype()

    Knowing Type with gettype()

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    22/79

    Variables offer a flexible way of storingdata. You can change their values and thetype of data they store at any time. If,however, you want to work with a value thatyou do not want to alter throughout yourscript's execution, you can define aconstant. define( "CONSTANT_NAME", 42 );

    e.g.

    define ( "USER", "Gerald" );print "Welcome ".USER;

    Note: There is $ in constant.

    Ardent Collaborations

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    23/79

    function some_function( $argument1, $argument2 ){

    // function code here

    }

    Ardent Collaborations

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    24/79

    A Variable Declared Within a Function IsUnavailable Outside the Function Variables Defined Outside Functions AreInaccessible from Within a Function by Default. Accessing Global Variables with the globalStatement.

    Ardent Collaborations

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    25/79

    Ardent Collaborations

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    26/79

    print (), echo() may be used as a function.

    Max()

    Min()

    Abs(-100) round(13.64) //14

    Rand() //create random number

    Ceil(12.3) // 13

    Floor(12.3) //12 include(url")

    require(url)

    Ardent Collaborations

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    27/79

    The two constructs are identical in every wayexcept how they handle failure. They bothproduce a Warning, but require() results in aFatal Error.

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    28/79

    An arrayis a list variable. That is, a variablethat contains multiple elements indexed bynumbers or strings. It enables you to store,order, and access many values under onename.

    Each item in an array is commonly referredto as an element. Each element can beaccessed directly via its index. An index toan array element can be either a number or

    a string. By default, array elements are indexed by

    number starting at zero

    Ardent Collaborations

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    29/79

    1. Defining Arrays with the array() Function$users = array ("Raja", "Rohan", "Rohit",

    "Ritesh" );

    print "$users[2]";

    1. Defining or Adding to Arrays with theArray Identifier$users[ ] = " Bert";

    $users[ ] = " Sharon";

    $users[ ] = " Betty";

    $users[ ] = " Harry";

    print "$users[2]";

    Ardent Collaborations

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    30/79

    Arrays indexed by strings are known as associativearrays.1. Defining Associative Arrays with the array()Function$character = array

    (name=>"bob",occupation=>"superhero",age=>30);

    print $character[age];

    1. Directly Defining or Adding to an AssociativeArray$character[name] = "bob";$character[occupation] = "superhero";$character[age] = 30;

    print $character[occupation];

    Ardent Collaborations

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    31/79

    Arrays that contain arrays as their elementsare known as multidimensional arrays.

    Ardent Collaborations

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    32/79

    We can access an element of an array byusing its index:

    print $user[4]

    count() returns the number of elements in anarray.

    $users = array ("Bert", "Sharon",

    "Betty", "Harry" );

    print $users[count($users) 1];

    Ardent Collaborations

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    33/79

    Syntax:

    foreach( $array as $temp ){

    //...

    } Example:

    $users = array ("Bert", "Sharon","Betty", "Harry" );

    foreach ( $users as $val ) {print "$val
    ";

    }

    Ardent Collaborations

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    34/79

    Syntax:foreach( $array as $key=>$value ){

    //...

    }

    Example:$character = array

    (name=>"bob",occupation=>"superhero",age=>30);

    foreach ( $character as $key=>$val ) {

    print "$key = $val
    ";}

    Ardent Collaborations

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    35/79

    Joining Two Arrays with array_merge() accepts two or more arrays and returns a merged array combining alltheir elements.

    $first = array("a", "b", "c");$second = array(1,2,3);

    $third = array_merge( $first, $second );

    foreach ( $third as $val ){

    print "$val
    ";

    }

    Adding Multiple Variables to an Array with array_push() accepts an array and any number of further parameters and returns the

    total number of elements in the array it transforms.$first = array("a", "b", "c");$total = array_push( $first, 1, 2, 3 );print "There are $total elements in \$first

    ";foreach ( $first as $val ){print "$val
    ";}

    Ardent Collaborations

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    36/79

    Removing the First Element of an Array with array_shift() removes and returns the first element of an array$an_array = array("a", "b", "c");while ( count( $an_array) ){$val = array_shift( $an_array);print "$val
    ";

    print "there are ".count($an_array)." elements in \$an_array
    ";}

    Slicing Arrays with array_slice() accepts an array as an argument, a starting position (offset), and an

    (optional) length and returns a new array.$first = array("a", "b", "c", "d", "e", "f");$second = array_slice($first, 2, 3);foreach ( $second as $var ){print "$var
    ";}

    Ardent Collaborations

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    37/79

    Sorting Numerically Indexed Arrays with sort()$an_array = array("x","a","f","c");sort( $an_array);foreach ( $an_array as $var ){print "$var
    ";}

    Sorting an Associative Array by Value with asort()$first = array("first"=>5,"second"=>2,"third"=>1);asort( $first );foreach ( $first as $key => $val ){print "$key = $val
    ";

    } Sorting an Associative Array by Key with ksort()

    ksort( $first );

    Ardent Collaborations

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    38/79

    When PHP processes a page, it checks forGET, POST, Cookie, Server and Environmentvariables, this information is collectively

    known as EGPCS. It creates an array called $GLOBALSforeach ( $GLOBALS as $key=>$value ){

    print "$key == $value
    ";

    }

    Ardent Collaborations

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    39/79

    PHP creates 5 global arrays:1. $HTTP_GET_VARS or $_GET

    2. $HTTP_POST_VARS or $_POST

    3. $HTTP_COOKIE_VARS or $_COOKIE4. $HTTP_SERVER_VARS or $_SERVER

    5. $HTTP_ENV_VARS or $_ENV

    Ardent Collaborations

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    40/79

    For fetching request data, we have global arrayslike $_GET, $_POST etc.

    Response is sent by the server to the client.

    header() is used to send a raw HTTP header.

    Syntax:

    voidheader ( string $string [, bool $replace=true [, int $http_response_code ]] )

    Ardent Collaborations

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    41/79

    There are two special-case header calls "HTTP/

    used to figure out the HTTP status code to send. header("HTTP/1.0 404 Not Found");

    "Location: returns a REDIRECT(302) status code to the browser.

    header("Location: http://www.example.com/");

    Can be used in some other ways also.

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    42/79

    An example:

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    43/79

    Word: header("Content-type: application/msword");

    header("Content-Disposition:attachment;Filename=document_name.doc");

    Excel: header("Content-type: application/vnd.ms-excel");

    header("Content-Disposition:

    attachment;Filename=document_name.xls");

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    44/79

    extension=php_pdf.dll Add this line in the php.ini file to create pdf in

    runtime.

    An example:

    Click here

    http://d/imp%20doc/C:/wamp/www/hello/index.phphttp://d/imp%20doc/C:/wamp/www/hello/index.php
  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    45/79

    $server = "localhost";$username = "root";

    $password = "";

    $database = ardent";

    @mysql_connect ($server, $username,$password) OR die ('Could not connect to

    MySQL: ' . mysql_error() );@mysql_select_db ($database) OR die ('Could

    not select the database: ' . mysql_error() );

    Ardent Collaborations

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    46/79

    connect$sql = "INSERT INTO std VALUES(1,'Rohit','Kolkata')";

    $results = mysql_query ( $sql);if($results)

    {echo "Added";}else{

    echo "Sorry, There is a temporary problem, Tryagain.". mysql_error();}

    Ardent Collaborations

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    47/79

    $sql = "SELECT * from std";$result = mysql_query($sql);

    while ($row = mysql_fetch_array($result)) {

    echo "$row[roll]";echo "$row[name] ";echo "$row[addr] ";

    }

    Ardent Collaborations

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    48/79

    Include() and require() function enables usto incorporate files into your PHPdocuments.

    include_once() and require_once()includes the file only once.

    Ardent Collaborations

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    49/79

    Checking for Existence withfile_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

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    50/79

    DeterminingFile Size with filesize()

    last accessed time with fileatime().

    e.g.

    $atime = fileatime( "test.txt" );rint "test.txt was last accessed on ";

    rint date("D d M Y g:i A", $atime);

    the modification date of a file with thefunction filemtime()

    Ardent Collaborations

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    51/79

    touch() : create a file

    If the file already exists, the contents are notdisturbed, but the modification date is updated

    to the time at which the function executed.e.g. touch("myfile.txt");

    unlink() :remove an existing file.

    e.g. unlink("myfile.txt");

    Ardent Collaborations

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    52/79

    fopen()

    fopen() requires a string containing the file path,followed by a string containing the mode in which thefile is to be opened.

    Modes:

    read ('r'), write ('w'), and append ('a').

    for reading:$fp = fopen( "test.txt", 'r' );

    for writing: $fp = fopen( "test.txt", 'w' );

    for appending : $fp = fopen( "test.txt", 'a' );

    Ardent Collaborations

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    53/79

    Line by Line: fgets(file pointer, no of bytes) Reading Arbitrary Amounts of Data

    from a File with fread()

    feof(file pointer) tells the end of filewhile ( ! feof( $fp ) ) {

    $line = fgets( $fp, 1024 );

    print "$line
    ";

    }

    Ardent Collaborations

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    54/79

    fgetc(file pointer) reads a character

    fseek(file pointer, int offset)

    change the currentposition within a file.

    Ardent Collaborations

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    55/79

    $fp = fopen( "test.txt", "w" ) $fp = fopen( "test.txt", "a" )

    fwrite()

    fputs()Both of them accepts a file pointer and a string.

    Ardent Collaborations

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    56/79

    Ardent Collaborations

    The integer returned by time() represents the

    number of seconds elapsed sincemidnight GMT on January 1, 1970. This

    moment is known as the UNIX epoch, and

    the number of seconds that have elapsed since

    then is referred to as a time stamp.

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    57/79

    Ardent Collaborations

    Getdate()returns anassociative

    array

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    58/79

    Ardent Collaborations

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    59/79

    Ardent Collaborations

    Date() returns string

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    60/79

    Ardent Collaborations

    returns a time stamp that you can then use with

    date() or getdate().

    mktime() accepts up to six integer arguments

    in the following order: hour minute second

    month day of month year

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    61/79

    Ardent Collaborations

    Checkdate() accepts three integers:month, day, and year.

    checkdate() returns true if the date isvalid.

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    62/79

    Ardent Collaborations

    @mail( $to, $subject, $message, $headers )$to =email id

    $subject = subject of the mail$message = body of the mail

    $headers = "From: [email protected]\r\nReply-To: [email protected]";

    It returns true, if mail sent successfully.

    mailto:[email protected]:[email protected]
  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    63/79

    Ardent Collaborations

    Choose a file to upload:

    For binary data enctype must be multipart/form-data

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    64/79

    Ardent Collaborations

    the uploaded file exists in a temporary storage

    area on the server. If the file is not moved to adifferent location it will be destroyed! To saveour precious file we are going to need to makeuse of the $_FILES associative array.

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    65/79

    Ardent Collaborations

    It has two parameter, first s the form's input name andthe 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 uploadedfile

    $_FILES["file"]["tmp_name"] - the name of thetemporary copy of the file stored on the server

    $_FILES["file"]["error"] - the error code resulting fromthe file upload

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    66/79

    Ardent Collaborations

    move_uploaded_file($_FILES['uploadedfile']

    ['tmp_name'], $target_path)

    $target_path is the location where to save the

    file

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    67/79

    Ardent Collaborations

    $target_path = "uploads/";

    $target_path = $target_path . $_FILES['uploadedfile']['name'];

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

    echo "
    The file ". $_FILES['uploadedfile']['name']. "has been uploaded";

    else

    echo "
    There was an error uploading the file, pleasetry again!";

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    68/79

    Ardent Collaborations

    Print a string using

    print echo printf

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    69/79

    Ardent Collaborations

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    70/79

    Ardent Collaborations

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    71/79

    Ardent Collaborations

    chr() Return a specific character by ASCII

    string convert_uuencode ( string $data ):encodes a string using the uuencodealgorithm.

    string convert_uudecode ( string $data ):

    decodes a uuencoded string

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    72/79

    Ardent Collaborations

    crypt One-way string encryption(hashing): return an encrypted string usingthe standard Unix DES-based encryption

    algorithm.

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    73/79

    Ardent Collaborations

    md5() Calculate the md5 hash of a string:Calculates the MD5 hash of str using the RSA

    Data Securitysha1 Calculate the sha1 hash of a string:Calculates the sha1 hash of str using the USSecure Hash Algorithm 1.

    hash Generate a hash value (message digest):it takes 2 args ( string $algo , string $data).

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    74/79

    Ardent Collaborations

    oin array elements with a glue string.

    $array = array('Rohit', 'Sharma', 'Kolkata');$comma_separated = join(",", $array);

    echo $comma_separated; //

    Rohit,Sharma,Kolkata

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    75/79

    Ardent Collaborations

    Returns an array of strings, each of which is asubstring of string formed by splitting it on

    boundaries formed by the string delimiter .

    $str = "Rohit,Sharma,Kolkata";

    $ar=explode("," , $str);

    print_r($ar);

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    76/79

    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() - Strip whitespace (or other

    characters) from the end of a string

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    77/79

    Ardent Collaborations

    str_replace: Replace all occurrences of the

    search string with the replacement string str_ireplace Case-insensitive version ofstr_replace().

    str_replace ( $search , $replace , $subject)

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    78/79

    Ardent Collaborations

    Pad a string to a certain length with anotherstringstring str_pad ( string $input , int $pad_length [, string$pad_string= " " [, int $pad_type= STR_PAD_RIGHT ]] )

    This functions returns the input string padded on the left,the right, or both sides to the specified padding length. Ifthe optional argument pad_string is not supplied, the inputis padded with spaces, otherwise it is padded withcharacters from pad_string up to the limit.

    Optional argument pad_type can be STR_PAD_RIGHT,STR_PAD_LEFT, or STR_PAD_BOTH. If pad_type is notspecified it is assumed to be STR_PAD_RIGHT.

  • 8/7/2019 _TND_147b6c446d0f9c0d6f9a6bc786500862dce26509

    79/79

    string str_repeat ( string $input , int $multiplier )

    Returns input repeated multiplier times.