Venciity

Email CensorShip

Aug 24th, 2014
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <title></title>
  5.     <style>
  6.         label, textarea, input {
  7.             display: block;
  8.         }
  9.         textarea {
  10.             width: 300px;
  11.             height: 200px;
  12.         }
  13.     </style>
  14. </head>
  15. <body>
  16. <form method="get" action="">
  17.     <label>Text:</label>
  18.     <textarea name="text">Hi, I'm an air-conditioner technician, so if you need any assistance you can contact me at [email protected] .
  19.         Secondary email: [email protected] or at [email protected] OR [email protected]</textarea>
  20.     <label>Blacklist:</label>
  21.     <textarea name="blacklist">*.bg
  22.         [email protected]
  23.         *.com</textarea>
  24.     <input type="submit" />
  25. </form>
  26. <?php
  27. function getReplacement($match , $blacklist) {
  28.     preg_match("/(\\..*)/" , $match , $domain); // get domain from current match
  29.     $dom = "*" . $domain[0]; // get domain with * before it
  30.     if (in_array($dom, $blacklist) || in_array($match , $blacklist)) {
  31.         return str_pad('', strlen($match), '*'); // encode domain/match from blacklist
  32.     }
  33.     else {
  34.         return "<a href=\"mailto:" . $match . "\">$match</a>";
  35.     }
  36. }
  37.     if (isset($_GET['text']) && isset($_GET['blacklist'])) {
  38.         $textArea = $_GET['text'];
  39.         $bl = $_GET['blacklist']; // get value from text area with name "blacklist"
  40.         //var_dump($bl) . "</br>";
  41.         $blacklist = preg_split("/\\s/", $bl, -1, PREG_SPLIT_NO_EMPTY); // split value from $bl by empty spaces , this return array of blacklist values
  42.         //var_dump($blacklist) . "</br>" ;
  43.         $pattern = "/[a-zA-Z0-9_+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+/"; // pattern for valid e-mails
  44.         preg_match_all($pattern, $textArea, $matches); // save the emails in variable $matches by $pattern.
  45.         //var_dump($matches) . "</br>";
  46.         foreach ($matches[0] as $match) {
  47.             $replacement = getReplacement($match , $blacklist); // get replacement
  48.             $textArea = str_replace($match, $replacement, $textArea); // replace current replacement in textArea
  49.         }
  50.         echo "<p>$textArea</p>";
  51.     }
  52. ?>
  53. </body>
  54. </html>
Advertisement
Add Comment
Please, Sign In to add comment