Print specific string 123456789 to a specific format 12xxxxx89 in PHP -



Print specific string 123456789 to a specific format 12xxxxx89 in PHP -

i want print string in specific format :

<?php $var = "123456789"; echo $var; //expected output 12xxxxx89; ?>

want show first 2 , lastly 2 characters string , show others in x format.how can ?

easy

echo substr_replace($var, str_repeat('x', max(strlen($var) - 4, 0)), 2, -2);

this should handle strings @ or below 4 characters in length too.

demo ~ eval.in

links functions:

substr_replace() str_repeat() strlen() max()

php string

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -