Mask String

Mask a string showing only the last few characters, useful for credit cards or SSNs.

Code

Utilities
str_repeat($maskChar, strlen($str) - $visibleChars) . substr($str, -$visibleChars);

Parameters

The string to mask.

Number of characters to show at the end.

Character to use for masking.

Server

More PHP Snippets