How can I remove the first 4 characters of a string using PHP?
function String2Stars($string='',$first=0,$last=0,$rep='*'){
$begin = substr($string,0,$first);
$middle = str_repeat($rep,strlen(substr($string,$first,$last)));
$end = substr($string,$last);
$stars = $begin.$middle.$end;
return $stars;
}
example
$string = 'abcdefghijklmnopqrstuvwxyz';
echo String2Stars($string,5,-5); // abcde****************vwxyz
$num = "+918883967576";
$str = substr($num, 3);
echo $str;
Output:8883967576
use php's built in substr function...
$result = substr("This World", 4);
//will return " World"
If you’re using a multi-byte character encoding and do not just want to remove the first four bytes like substr does, use the multi-byte counterpart mb_substr. This does of course will also work with single-byte strings.
You could use the substr function please check following example,
$string1 = "tarunmodi";
$first4 = substr($string1, 4);
echo $first4;
Output: nmodi
You could use the substr function to return a substring starting from the 5th character:
$str = "The quick brown fox jumps over the lazy dog."
$str2 = substr($str, 4); // "quick brown fox jumps over the lazy dog."