It returns part of a string
Example
<?php
echo substr(“phpcode”,2,4);
?>
Output
pcod
It returns part of a string
Example
<?php
echo substr(“phpcode”,2,4);
?>
Output
pcod
It replace text within a portion of a string
Example
<?php
echo substr_replace(“php code”,”codez”,4);
?>
Output
php codez
It counts the number of substring occurrences
Example
<?php
echo substr_count(“phpcode. phpcodez”,”code”);
?>
Output
2
It compares two strings from a specified start position
This function returns:
0 – if the two strings are equal
<0 – if string1 (from startpos) is less than string2
>0 – if string1 (from startpos) is greater than string2
If length is equal or greater than length of string1, this function returns FALSE
Example
<?php echo substr_compare("phpcodexc","phpcode",0); ?>
Output
2
It translate characters or replace substrings
Example
<?php
echo strtr(“One Two”,array(“One” => “PHP”, “Two” => “HTML”));
?>
Output
PHP HTML
It makes a string uppercase
Example
<?php
echo strtoupper(“PHPCode”);
?>
Output
PHPCODE
It makes a string lowercase
Example
<?php
echo strtolower(“PHPCode”);
?>
Output
phpcode
It splits a string into smaller strings
Example
<?php
$tokenVal = strtok(“php html js”, ” “);
while ($tokenVal != false) {
echo $tokenVal .” “;
$tokenVal =strtok(” “);
}
?>
Output
php html js
It finds the first occurrence of a string
Example
<?php
echo strstr(“phpcode”,”co”);
?>
Output
code
It returns the number of characters found in the string that contains only characters from the charlist.
Example
<?php
echo strspn(“phpcodephp”,”phpe”);
?>
Output
3