php - Replace username part in email addresses into asterisks -


how can convert username in email addresses asterisks. first , last letter in username stay , rest replaced (*).

example:

mhyunf@gmail.com 

into

m****f@gmail.com 

you can using arounds.

/(?!^).(?=[^@]+@)/ 
  • (?!^) negative behind. checks if character not preceded start of string. ensures first character not selected.

  • . matches single character.

  • (?=[^@]+@) positive ahead. ensures single character matched followed other @ ( ensured [^@] ) , @

regex demo

example

preg_replace("/(?!^).(?=[^@]+@)/", "*", "mhyunf@gmail.com") =>  m****f@gmail.com 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -