noister Posted April 15, 2009 Share Posted April 15, 2009 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 Link to comment https://forums.phpfreaks.com/topic/154157-solved-how-to-replace-email-address-to-a-specified-string/ Share on other sites More sharing options...
MasterACE14 Posted April 15, 2009 Share Posted April 15, 2009 <?php echo str_replace($string,$replace); ?> you just gotta find the string using regex, or substr(), or str_pos() or a combination of them. Link to comment https://forums.phpfreaks.com/topic/154157-solved-how-to-replace-email-address-to-a-specified-string/#findComment-810361 Share on other sites More sharing options...
noister Posted April 15, 2009 Author Share Posted April 15, 2009 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); Link to comment https://forums.phpfreaks.com/topic/154157-solved-how-to-replace-email-address-to-a-specified-string/#findComment-810375 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.