Link to home
Start Free TrialLog in
Avatar of BR
BRFlag for Türkiye

asked on

masking php string

I have a variable that holds the name and surname of the my user

I want to print the name on the screen with a mask like
$name=John Lanon

I'd like to show the only first letters and the others should be * instead of letter

I'd like to print it like J*** L****
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BR

ASKER

thank you Ray Paseur,
thank you so much
This is one of those questions with many paths to a solution, and also with many layers of underlying questions.  A good strategy might be to set up a test script that would allow you to test any new solution with a collection of names.  String processing is hard to get right because the incoming strings have so many variances, and our code needs to account for almost infinite variability.

The "rules" for English-language names permit such things as Leonard Pinth-Garnell, Dr. James Madison, BGen Warren Woods, Richard Allen, Jr., W. David Lawson, IV, Jack O'Rourke, Paul McDuffie, etc. and the final algorithm you choose would need to make sensible outputs from a variety of names.
Avatar of BR

ASKER

thank you Ray,
I'll read your article tonight.