str_split() works like explode() in some manner, it is used for splitting a string into an array.
Syntax:
str_split($mystring, length);
Example:
<?php
print_r(str_split("What"));
?>
Output:
Array
(
[0] => W
[1] => h
[2] => a
[3] => T
)
If you want to replace some specified characters with other characters in PHP, str_replace() is the best choice. It has many rules like:
Syntax:
str_replace(find, replace, string, count);
Example:
<?php
echo str_replace("How", "Dear", "How Di");
?>
Output:
How Dear
md5($str, raw);
<?php $mystr = "How Are You"; echo md5($mystr); ?>
9e227bb366c119c7f27a7115f0136f42
imlode(string_separator, array);
<?php
$arr = array("Hello", "Dear", "How", "Are", "You");
echo implode(" ", $arr);
?>
Hello Dear How Are You
explode(string_separator, $str, limit);
<?php
$mystr = "Hello Dear, How are you";
print_r(explode(" ", $mystr));
?>
Array ( [0] => Hello [1] => Dear, [2] => How [3] => are [4] => you )
This string function returns how many times a character (ASCII) appears in a string depending on the modes we specified.
By default, mode is 0 that returns an array with Key (ASCII Value) and Value (Number of Occurrences.
Mode 1 returns an array with same functionality as Mode 2, but it only lists appearance of characters which are greater than zero.
Mode 2 returns occurrence which are equal to zero.
Mode 3 returns string with difference characters used.
Mode 4 generates string of all unused characters.
count_chars($str, mode);
<?php $mystr = "Hello Dear, How are you"; print_r(count_chars($mystr, 0)); print_r(count_chars($mystr, 1)); print_r(count_chars($mystr, 2)); echo count_chars($mystr, 3); echo count_chars($mystr, 4); ?>