views:

63

answers:

3

Hi,

I am using cakephp. And I have textarea field where users paste 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 [email protected]..

I appreciate any help.

Thanks.

+3  A: 

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

$str = "My e-mail is [email protected] 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.

kovshenin
+1  A: 

You could: $string = "[email protected]";

$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.

horacv
A: 

this javascriptcode should do the job:

var content = editor.getContent({format:'text'});
content.replace("/([a-zA-Z0-9\._]+)(@[a-zA-Z0-9\-\.]+)/", "[email protected]");
editor.setContent(content); //you may alternatively choose to save it to a database
Thariama