Created by Nikul Shah
STRING FUNCTIONS
NIKUL SHAH 1
STRLEN()
• <?php
• echo strlen("Hello Nikul!");
• ?>
• /*output */
• 12
NIKUL SHAH 2
STR_WORD_COUNT()
• <?php
• echo str_word_count("Some people tend to forget that kindness and manners are free.");
• ?>
NIKUL SHAH 3
STRREV()
• <?php
• echo strrev("don't loss your hope.");
• ?>
NIKUL SHAH 4
STRPOS()
• strpos() function searches for a specific text within a string.
• If a match is found, the function returns the character position of the first match. If no
match is found, it will return FALSE.
• <?php
• echo strpos("Destiny works.", "works");
• ?>
NIKUL SHAH 5
STR_REPLACE ------ STRTR
• $search = array('A', 'B', 'C', 'D', 'E');
• $replace = array('B', 'C', 'D', 'E', 'F');
• $subject = 'A';
• $trans = array('A' => 'B','B'=>'C','C'=>'D','D'=>'E','E'=>'F');
• echo str_replace($search, $replace, $subject);
• echo "<br/>";
• echo strtr($subject,$trans);
NIKUL SHAH 6
• <?php
• echo str_replace("Nikul","Shah","Nik shah");
• ?>
NIKUL SHAH 7
ADDSLASHES()
• <?php
• $str=addslashes("today is 'monday'");
• echo "$str";
• ?>
• //output
• today is 'monday'
NIKUL SHAH 8
ADDCSLASHES()
• <?php
• $str=addcslashes("Nikul","k");
• echo "$str";
• ?>
• Be careful using addcslashes() on 0 (NULL), r (carriage return), n (newline), f (form feed),
t (tab) and v (vertical tab). In PHP, 0, r, n, t, f and v are predefined escape sequences.
NIKUL SHAH 9
CHR()
• The chr() function returns a character from the specified ASCII value.
• The ASCII value can be specified in decimal, octal, or hex values. Octal values are
defined by a leading 0, while hex values are defined by a leading 0x.
• <?php
$str = chr(43);
$str2 = chr(61);
echo("2 $str 2 $str2 4");
?>
NIKUL SHAH 10
EXPLODE()
• The explode() function breaks a string into an array.
• Note: The "separator" parameter cannot be an empty string.
• <?php
• $str="Hello my name is 'Nikul'";
• print_r (explode(" ",$str));
• print_r(explode(',',$str,0));
• ?>
• Using limits parameter it will returns no of elements.
• This function can not run on echo.
NIKUL SHAH 11
IMPLODE()
• implode() function returns a string from the elements of an array
• <?php
• $str =array('Hello','Nikul','How','are','You?');
• print_r(implode(",",$str));
• ?>.
NIKUL SHAH 12
JOIN()
• Joins array into string. Same as implode()
• <?php
• $im=array("nikul","Shah");
• echo (join(" ",$im));
• ?>
NIKUL SHAH 13
MD5()
• This function Calculates the MD5 hash of a string.
• <?php
• $im=array("nikul","Shah");
• echo md5(join(" ",$im));
• ?>
• 4994812ba7d125a30e2b9c04e7b7c014
NIKUL SHAH 14
NL2BR()
• Inserts HTML line breaks in front of each newline in a string
• <?php
• $n="Nikul nShah";
• echo nl2br($n);
• ?>
NIKUL SHAH 15
STR_SPLIT()
• This funciton splits string into an array.
• <?php
• $n="Nikul Shah";
• print_r(str_split($n));
?>
Array ( [0] => N [1] => i [2] => k [3] => u [4] => l [5] => [6] => S [7] => h [8] => a [9] => h )
NIKUL SHAH 16
STRCMP()
• The strcmp() function compares two strings.
• <?php
• echo strcmp("Nikul","Nik");
• ?>
• 2
NIKUL SHAH 17
STRTOLOWER()
• Converts string from uppercase to lower case.
• <?php
• echo strtolower("Nikul Shah");
• ?>
NIKUL SHAH 18
STRTOUPPER()
• Converts string from lowercase to upper case.
• <?php
• echo strtoupper("Nikul Shah");
• ?>
NIKUL SHAH 19
TRIM()
• This function removes the while space.
• <?php
• $str = "Nikul Shah!";
• echo $str . "<br>";
• echo trim($str,"Nik");
• ?>
• Nikul Shah!
ul Shah!
NIKUL SHAH 20
NUMBER_FORMAT()
• This function formats a number with grouped.
• <?php
• echo number_format("100000",1);
• ?>
• 100,000.0
NIKUL SHAH 21
RTIRM()
• Removes white space or other char. From right hand side of the string.
• <?php
• $str = "Nikul Shah!";
• echo $str . "<br>";
• echo rtrim($str,"l Sah!");
• ?>
• Nikul Shah!
Niku
NIKUL SHAH 22
STR_IREPLACE()
• Replaces some char of the string.
• <?php
• echo str_ireplace("Nikul", "hi","hey hello");
• ?>
• hey hello
NIKUL SHAH 23
STR_REPEAT()
• str_repeat() function repeats a string a specified number of times.
• <?php
• echo str_repeat("Nikul",10);
• ?>
• NikulNikulNikulNikulNikulNikulNikulNikulNikulNikul
NIKUL SHAH 24
STR_REPLACE()
• <?php
• $r=array("hello","hey", "Nikul","hello");
• print_r(str_replace("hello","hi",$r,$i));
• echo"<br>";
• echo "replacements are :$i";
• ?>
• Array ( [0] => hi [1] => hey [2] => Nikul [3] => hi )
replacements are :2
NIKUL SHAH 25
STR_SHUFFLE()
• <?php
• echo str_shuffle("Nikul");
• ?>
• ikuNl
NIKUL SHAH 26
STR_WORD_COUNT()
• Counts the word in the string.
• <?php
• echo str_word_count("Nikul Shah");
• ?>
• 2
NIKUL SHAH 27
STRCASECMP()
<?php
• echo strcasecmp("Nikul","Nikul");
• ?>
• 0 If this function returns 0, the two strings are equal.
• 0 - if the two strings are equal
• <0 - if string1 is less than string2
• >0 - if string1 is greater than string2
NIKUL SHAH 28
STR_PAD()
• <?php
• $str = "Hello Nikul";
• echo str_pad($str,40,".");
• ?>
• Hello Nikul.............................
NIKUL SHAH 29
STRCSPN()
• Retruns the no of char found in a string before any part of some specified char are found.
• <?php
• $str = "Hello Nikul";
• echo strcspn($str,"N");
• ?>
• 6
NIKUL SHAH 30
STRCHR()
• Finds the first occurrence of a string inside another string . Alias strstr().
• This is case sensitive.
• <?php
• $str = "Hello Nikul";
• echo strchr($str,“Nikul");
• ?>
NIKUL SHAH 31
STRISTR()
• Finds the first occurrence of a string inside another string . Alias strstr().
• This is case insensitive.
• $str = "Hello Nikul";
• echo strchr($str,“nikul");
• ?>
NIKUL SHAH 32
STRIPOS()
• stripos() function finds the position of the first occurrence of a string inside another string.
• <?php
• echo stripos("today is Sunday","Sunday");
• ?>
NIKUL SHAH 33
STRSPN()
• Returns the number of characters found in a string that contains only characters from a
specified charlist
• <?php
• echo strspn("Nikul","ikul");
• ?>
• 0
NIKUL SHAH 34
CONVERT_UUENCODE()
• <?php
$str = "Hello Nikul!";
echo convert_uuencode($str);
?>
• convert_uudecode()
• $decodeString = convert_uudecode($encodeString);
echo $decodeString;
NIKUL SHAH 35
ENJOYED !!! ???
NEXT ARRAY.
BY NIKUL SHAH
NIKUL SHAH 36

String functions

  • 1.
    Created by NikulShah STRING FUNCTIONS NIKUL SHAH 1
  • 2.
    STRLEN() • <?php • echostrlen("Hello Nikul!"); • ?> • /*output */ • 12 NIKUL SHAH 2
  • 3.
    STR_WORD_COUNT() • <?php • echostr_word_count("Some people tend to forget that kindness and manners are free."); • ?> NIKUL SHAH 3
  • 4.
    STRREV() • <?php • echostrrev("don't loss your hope."); • ?> NIKUL SHAH 4
  • 5.
    STRPOS() • strpos() functionsearches for a specific text within a string. • If a match is found, the function returns the character position of the first match. If no match is found, it will return FALSE. • <?php • echo strpos("Destiny works.", "works"); • ?> NIKUL SHAH 5
  • 6.
    STR_REPLACE ------ STRTR •$search = array('A', 'B', 'C', 'D', 'E'); • $replace = array('B', 'C', 'D', 'E', 'F'); • $subject = 'A'; • $trans = array('A' => 'B','B'=>'C','C'=>'D','D'=>'E','E'=>'F'); • echo str_replace($search, $replace, $subject); • echo "<br/>"; • echo strtr($subject,$trans); NIKUL SHAH 6
  • 7.
    • <?php • echostr_replace("Nikul","Shah","Nik shah"); • ?> NIKUL SHAH 7
  • 8.
    ADDSLASHES() • <?php • $str=addslashes("todayis 'monday'"); • echo "$str"; • ?> • //output • today is 'monday' NIKUL SHAH 8
  • 9.
    ADDCSLASHES() • <?php • $str=addcslashes("Nikul","k"); •echo "$str"; • ?> • Be careful using addcslashes() on 0 (NULL), r (carriage return), n (newline), f (form feed), t (tab) and v (vertical tab). In PHP, 0, r, n, t, f and v are predefined escape sequences. NIKUL SHAH 9
  • 10.
    CHR() • The chr()function returns a character from the specified ASCII value. • The ASCII value can be specified in decimal, octal, or hex values. Octal values are defined by a leading 0, while hex values are defined by a leading 0x. • <?php $str = chr(43); $str2 = chr(61); echo("2 $str 2 $str2 4"); ?> NIKUL SHAH 10
  • 11.
    EXPLODE() • The explode()function breaks a string into an array. • Note: The "separator" parameter cannot be an empty string. • <?php • $str="Hello my name is 'Nikul'"; • print_r (explode(" ",$str)); • print_r(explode(',',$str,0)); • ?> • Using limits parameter it will returns no of elements. • This function can not run on echo. NIKUL SHAH 11
  • 12.
    IMPLODE() • implode() functionreturns a string from the elements of an array • <?php • $str =array('Hello','Nikul','How','are','You?'); • print_r(implode(",",$str)); • ?>. NIKUL SHAH 12
  • 13.
    JOIN() • Joins arrayinto string. Same as implode() • <?php • $im=array("nikul","Shah"); • echo (join(" ",$im)); • ?> NIKUL SHAH 13
  • 14.
    MD5() • This functionCalculates the MD5 hash of a string. • <?php • $im=array("nikul","Shah"); • echo md5(join(" ",$im)); • ?> • 4994812ba7d125a30e2b9c04e7b7c014 NIKUL SHAH 14
  • 15.
    NL2BR() • Inserts HTMLline breaks in front of each newline in a string • <?php • $n="Nikul nShah"; • echo nl2br($n); • ?> NIKUL SHAH 15
  • 16.
    STR_SPLIT() • This funcitonsplits string into an array. • <?php • $n="Nikul Shah"; • print_r(str_split($n)); ?> Array ( [0] => N [1] => i [2] => k [3] => u [4] => l [5] => [6] => S [7] => h [8] => a [9] => h ) NIKUL SHAH 16
  • 17.
    STRCMP() • The strcmp()function compares two strings. • <?php • echo strcmp("Nikul","Nik"); • ?> • 2 NIKUL SHAH 17
  • 18.
    STRTOLOWER() • Converts stringfrom uppercase to lower case. • <?php • echo strtolower("Nikul Shah"); • ?> NIKUL SHAH 18
  • 19.
    STRTOUPPER() • Converts stringfrom lowercase to upper case. • <?php • echo strtoupper("Nikul Shah"); • ?> NIKUL SHAH 19
  • 20.
    TRIM() • This functionremoves the while space. • <?php • $str = "Nikul Shah!"; • echo $str . "<br>"; • echo trim($str,"Nik"); • ?> • Nikul Shah! ul Shah! NIKUL SHAH 20
  • 21.
    NUMBER_FORMAT() • This functionformats a number with grouped. • <?php • echo number_format("100000",1); • ?> • 100,000.0 NIKUL SHAH 21
  • 22.
    RTIRM() • Removes whitespace or other char. From right hand side of the string. • <?php • $str = "Nikul Shah!"; • echo $str . "<br>"; • echo rtrim($str,"l Sah!"); • ?> • Nikul Shah! Niku NIKUL SHAH 22
  • 23.
    STR_IREPLACE() • Replaces somechar of the string. • <?php • echo str_ireplace("Nikul", "hi","hey hello"); • ?> • hey hello NIKUL SHAH 23
  • 24.
    STR_REPEAT() • str_repeat() functionrepeats a string a specified number of times. • <?php • echo str_repeat("Nikul",10); • ?> • NikulNikulNikulNikulNikulNikulNikulNikulNikulNikul NIKUL SHAH 24
  • 25.
    STR_REPLACE() • <?php • $r=array("hello","hey","Nikul","hello"); • print_r(str_replace("hello","hi",$r,$i)); • echo"<br>"; • echo "replacements are :$i"; • ?> • Array ( [0] => hi [1] => hey [2] => Nikul [3] => hi ) replacements are :2 NIKUL SHAH 25
  • 26.
    STR_SHUFFLE() • <?php • echostr_shuffle("Nikul"); • ?> • ikuNl NIKUL SHAH 26
  • 27.
    STR_WORD_COUNT() • Counts theword in the string. • <?php • echo str_word_count("Nikul Shah"); • ?> • 2 NIKUL SHAH 27
  • 28.
    STRCASECMP() <?php • echo strcasecmp("Nikul","Nikul"); •?> • 0 If this function returns 0, the two strings are equal. • 0 - if the two strings are equal • <0 - if string1 is less than string2 • >0 - if string1 is greater than string2 NIKUL SHAH 28
  • 29.
    STR_PAD() • <?php • $str= "Hello Nikul"; • echo str_pad($str,40,"."); • ?> • Hello Nikul............................. NIKUL SHAH 29
  • 30.
    STRCSPN() • Retruns theno of char found in a string before any part of some specified char are found. • <?php • $str = "Hello Nikul"; • echo strcspn($str,"N"); • ?> • 6 NIKUL SHAH 30
  • 31.
    STRCHR() • Finds thefirst occurrence of a string inside another string . Alias strstr(). • This is case sensitive. • <?php • $str = "Hello Nikul"; • echo strchr($str,“Nikul"); • ?> NIKUL SHAH 31
  • 32.
    STRISTR() • Finds thefirst occurrence of a string inside another string . Alias strstr(). • This is case insensitive. • $str = "Hello Nikul"; • echo strchr($str,“nikul"); • ?> NIKUL SHAH 32
  • 33.
    STRIPOS() • stripos() functionfinds the position of the first occurrence of a string inside another string. • <?php • echo stripos("today is Sunday","Sunday"); • ?> NIKUL SHAH 33
  • 34.
    STRSPN() • Returns thenumber of characters found in a string that contains only characters from a specified charlist • <?php • echo strspn("Nikul","ikul"); • ?> • 0 NIKUL SHAH 34
  • 35.
    CONVERT_UUENCODE() • <?php $str ="Hello Nikul!"; echo convert_uuencode($str); ?> • convert_uudecode() • $decodeString = convert_uudecode($encodeString); echo $decodeString; NIKUL SHAH 35
  • 36.
    ENJOYED !!! ??? NEXTARRAY. BY NIKUL SHAH NIKUL SHAH 36