fork download
  1. <?php
  2.  
  3. function maskIp($value) {
  4. $len = strlen($value);
  5. $j = 0;
  6.  
  7. for ($i = $len - 1; $j < 4 && $i > -1; --$i) {
  8. if (ctype_digit($value{$i})) {
  9. ++$j;
  10. $value{$i} = '*';
  11. }
  12. }
  13.  
  14. return $value;
  15. }
  16.  
  17. echo maskIp('127.0.0.100'), PHP_EOL;
  18. echo maskIp('127.0.0.10'), PHP_EOL;
  19. echo maskIp('127.0.0.1'), PHP_EOL;
  20. echo maskIp('127.0.255.100'), PHP_EOL;
  21. echo maskIp('127.0.25.100'), PHP_EOL;
Success #stdin #stdout 0.01s 52488KB
stdin
Standard input is empty
stdout
127.0.*.***
127.*.*.**
12*.*.*.*
127.0.25*.***
127.0.2*.***