Safcode Institute by Sir Safder





  • String Functions

    There are many string functions in php, but i explain only 
    most usable & important string function in PHP are given below:
    
    

    1. String Function "strlen()":

    The "strlen()" function in PHP return the length of the characters of an array. Note: strlen() count the character length with white space. For example: <?php echo strlen("SAFCODE By Sir Safder"); ?> Output: 21

    2. String Function "uuencode()":

    The String function "uuencode()" in PHP is used to encodes a string using the uuencode algorithm. Its means uuencode function convert your normal text into endoded form. <?php $msg = "Safcode - Code Your Ideas"; echo convert_uuencode($msg); ?> Output: 53!M;W5E(#UY($SM6&MF

    3. String Function "uudecode()":

    The String function "uudecode()" in PHP is used to decode a uuencoded string. Its means uudecode function convert your uuencoded form text into normal text. <?php $msg = "53!M;W5E(#UY($SM6&MF"; echo convert_uudecode($msg); ?> Output: Safcode - Code Your Ideas

    4. String Function "implode()":

    The implode() function returns a string from the array. Example: <?php $arr = array("HTML", "CSS", "PHP"); echo implode(" ",$arr); ?> Output: HTML CSS PHP

    5. String Function "md5()":

    The md5() function used to calculates the MD5 hash of a string. The md5() function in PHP uses the RSA Data Security, Inc. MD5 Message-Digest Algorithm. It returns the hash as a 32-character hexadecimal number. Example: <?php $str = "Hello"; echo md5($str); ?> Output: 8b1a9953c4611296a827abf8c47804d7

    6. String Function "strcmp()":

    The strcmp() function in PHP compares two values and return the answer is 0 or 1, means true or false. It is a case sensitive. Example: <?php echo strcmp("Safcode","Safcode"); ?> Output: 0 //its means true

    7. String Function "trim()":

    The trim() function in PHP erase whitespace and other characters from start to end of a string. <?php $str = "Hello World!"; echo $str . "<br>"; echo trim($str,"Hed!"); ?> Output: Hello World! llo Worl

    8. String Function "substr()":

    The substr() function in PHP returns a substring of a string. Substr() function contains three arguments two are necessary and last one is optional. Example1: <?php echo substr("Safcode By Sir Safder",11); //starting point 11 ?> Output: Sir Safder Example2: <?php echo substr("Hello world",0,5) //0 is a starting point and 5 is a ending point ?> Output: Hello

    9. String Function "str_shuffle()":

    The str_shuffle() function is used to shuffle all the character of a string. Its mean str_shuffle() function move the sequence of string in to randomly order. Example: <?php $abc="SAFCODE"; echo "Without Shuffle" .abc; echo "<br>"; echo "After Shuffle" .str_shuffle($abc); ?> Output: Without Shuffle: SAFCODE After Shuffle: OFDSEAC

    10. String Function "strtolower()":

    The strtolower() function is used to convert string into a lowercase. Example: <?php echo strtolower("HELLO WORLD."); ?> Output: hello world



  • You Can Also Watch Our Tutorial