vSouza

stringHelpers

Dec 5th, 2021
996
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. if (!function_exists('makeEmail')) {
  4.     function makeEmail(string $fullName): string
  5.     {
  6.         $faker = new \Faker\Generator();
  7.         $faker->addProvider(new Faker\Provider\Internet($faker));
  8.  
  9.         return (string) Str::of($fullName)
  10.             ->replace(' ', '.')
  11.             ->ascii()
  12.             ->lower()
  13.             ->replaceMatches('/[^a-zA-Z0-9_.]+/', '')
  14.             ->replaceMatches('/\.d[aeiou]\.+/', '.')
  15.             ->append(rand(1, 100))
  16.             ->append('@' . $faker->safeEmailDomain());
  17.     }
  18. }
  19.  
RAW Paste Data