I have a variable containing a string of digits, I would like to replace every digit but the last 4 with a star (*). How would I do it?
Chris.
Replace all but last 4 digits in a string
Use [man]substr[/man] to extract all but the last four characters. Then append "****" to the result.
One possible solution:
$starred = substr_replace($number, str_repeat('*', strlen($number) - 4), 0, -4);