Guest User

Email CensorShip

a guest
Aug 24th, 2014
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  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. *.com</textarea>
  23. <input type="submit" />
  24. </form>
  25. <?php
  26. if (isset($_GET['text']) && isset($_GET['blacklist'])) {
  27. $textArea = $_GET['text'];
  28. $bl = $_GET['blacklist']; // get value from text area with name "blacklist"
  29. //var_dump($bl) . "</br>";
  30. $blacklist = preg_split("/\\s/", $bl, -1, PREG_SPLIT_NO_EMPTY); // split value from $bl by empty spaces , this return array of blacklist values
  31. //var_dump($blacklist) . "</br>" ;
  32. $pattern = "/[a-zA-Z0-9_+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+/"; // pattern for valid e-mails
  33. preg_match_all($pattern, $textArea, $matches); // save the emails in variable $matches by $pattern.
  34. //var_dump($matches) . "</br>";
  35. foreach ($matches[0] as $match) {
  36. $replacement = getReplacement($match , $blacklist); // get replacement
  37. $textArea = str_replace($match, $replacement, $textArea); // replace current replacement in textArea
  38. }
  39. echo "<p>$textArea</p>";
  40.  
  41. function getReplacement($match , $blacklist) {
  42. preg_match("/(\\..*)/" , $match , $domain); // get domain from current match
  43. $dom = "*" . $domain[0]; // get domain with * before it
  44. if (in_array($dom, $blacklist) || in_array($match , $blacklist)) {
  45. return str_pad('', strlen($match), '*'); // encode domain/match from blacklist
  46. }
  47. else {
  48. return "<a href=\"mailto:" . $match . "\">$match</a>";
  49. }
  50. }
  51. }
  52. ?>
  53. </body>
  54. </html>
Advertisement
Add Comment
Please, Sign In to add comment