“substr” is a function that can acquire a part of a specified character string.
here comes sample.
$char = "come on baby America";
echo substr($char, 1);
-> ome on baby America
If 1 is specified, character strings for the number of characters specified from o can be acquired.
$char = "502 bad gateway";
echo substr($char, 2, 7);
-> 2 bad g
From start position 2 to 7 characters.
mb_substr is also a function to retrieve a part of the specified character string, but what is the difference with substr?
mb_string can specify the character code of the character string in addition to specifying the starting position and the number of characters.
$char = "仮想通貨でおススメの通貨はありますか?";
echo substr($char, 2, 7, "utf-8");
-> Warning: substr() expects at most 3 parameters, 4 given in Standard input code on line 5
$char = "仮想通貨でおススメの通貨はありますか?";
echo mb_substr($char, 2, 7, "utf-8");
->通貨でおススメ
When using non-English, it’s easy to use, isn’t it?