Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function endsWith($email, $blackListItem)
- {
- $length = strlen($blackListItem);
- if ($length == 0) {
- return true;
- }
- return (substr($email, -$length) === $blackListItem);
- }
- //$text = $_GET['text'];
- //$blacklist = $_GET['blacklist'];
- $text = "Hi, I'm an air-conditioner technician, so if you need any assistance you can contact me
- at
- . Secondary email:
- or
- at
- OR
- ";
- $blacklist = "*.bg
- *.com";
- $blackListItems = preg_split("/[\*\s,]+/", $blacklist, -1, PREG_SPLIT_NO_EMPTY);
- preg_match_all("/[0-9A-Za-z+_-]+\@[0-9A-Za-z-]+\.[0-9A-Za-z-\.]+/" , $text, $matches);
- foreach ($matches[0] as $matchArr) {
- foreach ($blackListItems as $blackListItem) {
- if (endsWith($matchArr, $blackListItem)) {
- $matchReplKeys[] = $matchArr;
- }
- }
- }
- foreach ($matchReplKeys as $matchReplKey) {
- $asterix='';
- for ($i=0; $i<strlen($matchReplKey); $i++ ) {
- $asterix .= "*";
- }
- $text = str_replace($matchReplKey, $asterix, $text);
- }
- preg_match_all("/[0-9A-Za-z+_-]+\@[0-9A-Za-z-]+\.[0-9A-Za-z-\.]+/" , $text, $validEmails);
- foreach ($validEmails[0] as $validEmail) {
- $mailToTag = '<a href="mailto:'.$validEmail.'">'.$validEmail.'</a>';
- $text = str_replace($validEmail, $mailToTag, $text);
- }
- echo "<p>".$text."</p>";
Advertisement
Add Comment
Please, Sign In to add comment