DEV Community

Morcos Gad
Morcos Gad

Posted on

New Tips In Laravel

mask() - before() - after()

use Illuminate\Support\Str;

$str = 'marcosgaad@gmail.com';
Str::mask($str, '*', 4); // marc****************
Str::mask($str, '*', 4, 3); // marc***aad@gmail.com
Str::mask($str, '*', -4); // marcosgaad@gmail****
Str::mask($str, '*', -4, 3); // marcosgaad@gmail***m

$before = Str::before($str, '@'); // marcosgaad
Str::mask($before, '*', 0) . '@' . Str::after($str, '@'); // **********@gmail.com
Enter fullscreen mode Exit fullscreen mode

I hope you enjoy the code.

Discussion (1)

Collapse
tom1097 profile image
ToiPV

great !