It compares two strings (case-insensitive)
Example
<?php
if (strcasecmp(“phpcode”, “PHPCode”) == 0) {
echo ‘Strings are equal’;
}
?>
Output
Strings are equal
It compares two strings (case-insensitive)
Example
<?php
if (strcasecmp(“phpcode”, “PHPCode”) == 0) {
echo ‘Strings are equal’;
}
?>
Output
Strings are equal
It return the number of words in a string
Example
<?php
echo “<pre>”;
print_r(str_word_count(‘It return the number of words in a string’));
?>
Output
9
It convert a string to an array
Example
<?php
echo “<pre>”;
print_r(str_split(‘phpcode’,2));
?>
Output
Array
(
[0] => ph
[1] => pc
[2] => od
[3] => e
)
It randomly shuffles a string
Example
<?php
echo str_shuffle(‘phpcode’);
?>
Output
oehppdc
It perform the rot13 transform on a string
Example
<?php
echo str_rot13(‘PHP Code’);
?>
Output
CUC Pbqr
It replace all occurrences of the search string with another string
Example
<?php
echo str_replace(“phpcodez”, “phpcode”, “phpcodez welcomes you”);
?>
Output
phpcode welcomes you
It repeats a string
Example
<?php
echo str_repeat(“php code”, 5);
?>
Output
php codephp codephp codephp codephp code
It pads a string to a certain length with another string
Example
<?php
echo str_pad(“phpcode”,20,”z”);
?>
Output
phpcodezzzzzzzzzzzzz
It replaces some characters in a string (case-insensitive)
Example
<?php
echo str_ireplace(“phpcodez”, “phpcode”, “phpcodez”);
?>
Output
phpcode
It parse a CSV string into an array
Example
<?php
echo “<pre>”;
print_r(str_getcsv(“php,code”));
?>
Output
fiArray
(
[0] => php
[1] => code
)