Jump to content

[SOLVED] how to replace email address to a specified string...


noister

Recommended Posts

hi to all,

 

i want to make a function that replace found email address to a specified string...

 

which something like this...

 

function find_replace_email($string,$replace='[email protected]'){

 

// please help code here....

 

return $string;

 

}

 

 

echo find_replace_email("This is my [email protected]");

 

// which should display similar to: This is my [email protected]

 

 

My goal is to hide all emailaddress entered by the users...

 

 

Any help really appreciated.

 

noister

 

 

ok got it...

 

function find_replace_email($str)

{

$emails = array();

preg_match_all("/\b\w+\@\w+[\.\w+]+\b/", $str, $output);

foreach($output[0] as $email) array_push ($emails, strtolower($email));

if (count ($emails) >= 1){

return str_replace($emails,"[email protected]",$str);

}

else return $str;

}

 

# Sample string containing email addresses;

$str = "test [email protected] ha ha [email protected] bla bla [email protected]";

 

echo find_replace_email($str);

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.