Source: www.amitmerchant.com

Mask part of a string in Laravel 8.x

Category: Laravel, PHP, javascript

There comes a time when you would be in need of obfuscating a certain part of the string. For instance, to obfuscate the credit card’s digits except the last four or to mask specific parts of the phone number or email. The best way to do obfuscate/mask is by replacing the intended part of the string with the stars.

So, according to https://github.com/laravel/framework/pull/39393, this method mask() lets you mask a portion of a string with a repeated character like so.

* * @param string $string * @param string $character * @param int $index * @param int|null $length * @param string $encoding * @return string */ public static function mask( $string, $character, $index, $length = null, $encoding = 'UTF-8' )
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners