I want to get a phone number in this format
Your phone number ********8898 has been sent with a verification code..
PHP
I want to get a phone number in this format
Your phone number ********8898 has been sent with a verification code..
PHP
If you wanna mask middle part:
private function stringToSecret(string $string = NULL)
{
if (!$string) {
return NULL;
}
$length = strlen($string);
$visibleCount = (int) round($length / 4);
$hiddenCount = $length - ($visibleCount * 2);
return substr($string, 0, $visibleCount) . str_repeat('*', $hiddenCount) . substr($string, ($visibleCount * -1), $visibleCount);
}
Result:
If phonenumber length is more than 4, then you can do this:
substr_replace($number, str_repeat('*', strlen($number)-4), 0, -4);
If you want to also show the first digit:
substr_replace($number, str_repeat('*', strlen($number)-5), 1, -4);
Try this
$phone_number = '******' . substr( $phone_number, - 4);
echo $phone_number;
you can use substr :
$my_text = '12345678';
echo substr($my_text, 1); // 2345678