Function PHP Replace Digit Number Telephone

Wahyu Raja Butar-Butar Reply 05:42

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

Google+ Followers

Popular Posts

Translate