How can I show and hide the some numbers of a phone number by replacing it with *
like 0935***3256
by PHP?
EX:
09350943256 -> 0935***3256
09119822432 -> 0911***2432
09215421597 -> 0921***1597
...
$number = '09350943256';
echo str_pad(substr($number, -4), strlen($number), '*', STR_PAD_LEFT);
Top php code result is as: *******3256
but i want result as: 0935***3256
How is it?
Use *67 to hide your phone number Open your phone's keypad and dial * - 6 - 7, followed by the number you're trying to call. The free process hides your number, which will show up on the other end as “Private” or “Blocked” when reading on caller ID.
You have the option to block Caller ID either temporarily or permanently. To block your number from being displayed temporarily for a specific call: Enter *67. Enter the number you wish to call (including area code).
Call return (*69) automatically dials your last incoming call, whether the call was answered, unanswered or busy. Call within 30 minutes, during which you can still make and receive calls. To deactivate while waiting for the party you are trying to reach to become available, dial *89.
You could use substr and concat this way
to work for any $number with any number of n digit length
<?php
$number = "112222";
$middle_string ="";
$length = strlen($number);
if( $length < 3 ){
echo $length == 1 ? "*" : "*". substr($number, - 1);
}
else{
$part_size = floor( $length / 3 ) ;
$middle_part_size = $length - ( $part_size * 2 );
for( $i=0; $i < $middle_part_size ; $i ++ ){
$middle_string .= "*";
}
echo substr($number, 0, $part_size ) . $middle_string . substr($number, - $part_size );
}
The output if you make $number = "1" is * and if $number = "12" is *2 and for $number = "112222" is 11**22. and it goes on.
In short:
$phone = 01133597084;
$maskedPhone = substr($phone, 0, 4) . "****" . substr($phone, 7, 4);
// Output: 0113****7084
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With