How to extract email id from textarea field

I am using cakephp. And I have a textarea field where users insert data, I use the tinymce plugin to format the text. I warned users not to enter a phone number or email address inside the text box. But I do not want to risk it.

Is there a way to get the phone number and email from the text box and replace it with something like XXXX@gmail.com ..

I appreciate any help.

Thank.

+3
source share
2 answers

Something is wrong here to replace the email address with a hidden one:

$str = "My e-mail is shown@gmail.com Contact me for more details";
$str = preg_replace("/([a-zA-Z0-9\._]+)(@[a-zA-Z0-9\-\.]+)/", "hidden\\2", $str);
print($str);

, , . ( ) http://www.regexlib.com/ preg_replace.

+3

: $string = "blabla@blablabla.com";

$parts = explode("@",$string);

\\$parts[0] contains the local part

\\$parts[1] contains the domain.

, ( ), , RFC 822, "@" . : "bl @bla" @blablabla.com .

+1

Source: https://habr.com/ru/post/1772134/


All Articles