Luminova Framework

PHP Luminova: Mask Values for Display

Last updated: 2026-11-28 20:57:12

Hide portions of strings, email addresses, phone numbers, and card numbers before displaying them.

Use Mask to display part of a value, such as the final four digits of a payment card. The methods return display strings and count bytes where they slice the input. Avoid logging passwords or using the display result as a substitute for secure storage.


Usage

use Luminova\Utility\Mask;

echo Mask::email('[email protected]'); // am***@example.com
echo Mask::card('4111 1111 1111 1234'); // **** **** **** 1234

Class Definition

  • Full namespace: Luminova\Utility\Mask
  • This class is final.

Methods

position

Mask a string by position to hide part of it (e.g: mfk---*kld).

public static function position(
    string $string,
    string $masker = '*',
    string $position = 'center',
    ?int $limit = null
): string

Parameters:

ParameterTypeDescription
$stringstringString to mask.
$maskerstringMask character (default: "*").
$positionstringMasking position ("center", "left", or "right") (default: 'center').
$limitint\|nullMaximum number of characters to mask (default: null).

Return:

string - Return masked string.

Examples:

use Luminova\Utility\Mask;

echo Mask::position('ABCDEFGH'); // ABC**FGH
echo Mask::position('ABCDEFGH', position: 'left', limit: 3); // ***DEFGH
echo Mask::position('ABCDEFGH', masker: '#', position: 'right', limit: 3); // ABCDE###

email

Mask an email address to hide part of it (e.g [email protected]).

public static function email(
    string $email,
    string $masker = '*',
    int $visible = 2
): string

Parameters:

ParameterTypeDescription
$emailstringEmail address to mask.
$maskerstringMask character (default: "*").
$visibleintNumber of visible characters before masking (default: 2).

Return:

string - Return the masked email address.

Examples:

use Luminova\Utility\Mask;

echo Mask::email('[email protected]'); // am***@example.com
echo Mask::email('[email protected]', masker: '-', visible: 1); // [email protected]

phone

Keep the ending bytes visible and replace the preceding bytes with the mask. Input punctuation participates in the byte count. Use a positive visible count shorter than the input for partial masking. A count of zero or less masks the entire input.

public static function phone(
    string $phone,
    string $masker = '*',
    int $visible = 4
): string

Parameters:

ParameterTypeDescription
$phonestringPhone string.
$maskerstringMask string (default: '*').
$visibleintNumber of ending bytes to show (default: 4).

Return:

string - Masked value, or the original if it already fits within the visible count.

Examples:

use Luminova\Utility\Mask;

echo Mask::phone('2025550123'); // ******0123
echo Mask::phone('2025550123', masker: 'x', visible: 2); // xxxxxxxx23

card

Strip non-digits, mask the leading digits, and group the result in blocks of four. Use a positive visible count shorter than the digit count. A count of zero or less masks all digits.

public static function card(
    string $card,
    string $masker = '*',
    int $visible = 4
): string

Parameters:

ParameterTypeDescription
$cardstringCard number string.
$maskerstringMask string (default: '*').
$visibleintCount of ending digits to show (default: 4).

Return:

string - Masked card display, or the original when its digit count does not exceed the visible count.

Examples:

use Luminova\Utility\Mask;

echo Mask::card('4111 1111 1111 1234'); // **** **** **** 1234
echo Mask::card('4111-1111-1111-1234', masker: 'X', visible: 6); // XXXX XXXX XX11 1234

password

Mask the beginning of a password and retain a suffix when the visible count is between one and the byte length minus one. A count at least as large as the password length yields a fully masked string. A count of zero or less also masks the entire value. Avoid this method for redaction.

public static function password(string $password, int $visible = 3): string

Parameters:

ParameterTypeDescription
$passwordstringPassword string.
$visibleintNumber of ending bytes requested (default: 3).

Return:

string - Masked display string, subject to the visible-count behavior above.

Examples:

use Luminova\Utility\Mask;

// Use a fictional value to demonstrate the output.
echo Mask::password('DemoPass123'); // ********123
echo Mask::password('DemoPass123', visible: 11); // ***********