I want to print a string in specific format like :
<?php
$var = "123456789";
echo $var; //expected output 12xxxxx89;
?>
Want to show first two and last two characters from string and show others in x
format.How can i do that ?
I want to print a string in specific format like :
<?php
$var = "123456789";
echo $var; //expected output 12xxxxx89;
?>
Want to show first two and last two characters from string and show others in x
format.How can i do that ?
Easy
echo substr_replace($var, str_repeat('x', max(strlen($var) - 4, 0)), 2, -2);
This should handle strings at or below 4 characters in length too.
Demo ~ <kbd>eval.in</kbd>
Links to functions: