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

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners