Function PHP Replace Digit Number Telephone

Unknown Reply 5:42 AM

FUNCTION PHP STRLEN AND REGEX

This clue simple way to make that:
 
$n = 3;
$nohp = '08123456789';
for($i=$n; $i>=1; $i--)
{
$nohp[strlen($nohp)-$i] = 'X';
}
 
 
This expert way to make function dynamic:
 
function sensor($no_hp, $digit) {
$pola = '#([0-9]{'.$digit.'})$#';
$x = '';
for ($i=1; $i<=$digit; $i++) { $x .= 'X'; }
return preg_replace($pola, $x, $no_hp);
}
  
How to use that?
Example : sensor(081234567890,3) //3 means last digit of number

SQL VERSION

 SELECT REPLACE('085733634253', right('085733634253',3), 'xxx')

Related Posts

PHP 3820148361221259568
Comments
0 Comments
Facebook Comments by Media Blogger

Post a Comment

Search

Ikuti Channel Youtube Aku Yaa.. Jangan Lupa di subscribe. Terima kasih.

Popular Posts

Translate