开发者

How to extract the email id from textarea field

I am using cakephp. And I have textarea field where users paste 开发者_Python百科data, I using tinymce plugin to format text. I have warned users not to enter telephone number or email address inside the textarea. But, I dont want to take chances.

Is there a way I can extract the telephone number and email from textarea and replace it something like XXXX@gmail.com..

I appreciate any help.

Thanks.


Here's something off the top of my head for replacing the e-mail address with hidden:

$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);

The e-mail regex is not the best, but it's something that works for your example. You can get more interesting regexes (emails and phone numbers) at http://www.regexlib.com/ and use them with a simple preg_replace.


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

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

\\$parts[0] contains the local part

\\$parts[1] contains the domain.

Keep in mind that, (even though it is not usual), the format defined by RFC 822 allows the "@" symbol to appear within quotation marks. This means: "bl@bla"@blablabla.com is technically correct.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜