Advertisement
Guest User

2nd problem

a guest
Aug 28th, 2014
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.34 KB | None | 0 0
  1. <?php
  2.  
  3. $text = $_GET['text'];
  4. //var_dump($text);
  5. //$text = "Hi, I'm an air-conditioner technician, so if you need any assistance you can contact me at air-conditioners@gmail.com . Secondary email: kinky_technician@yahoo.in or at naked-screwdriver@abv.bg OR pesho@dir.tk";
  6. $blacklist  = $_GET['blacklist'];
  7. //$blacklist = '*.bg
  8. //pesho@dir.tk
  9. //*.com
  10. //';
  11. $pattern = '/[0-9A-Za-z\_\+\-]+@[0-9A-Za-z\-]+\.[0-9A-Za-z\-\.]+/';
  12.  
  13. preg_match_all($pattern, $text, $result);
  14. $blacklist = preg_split('/[\n\r]+/', $blacklist);
  15.  
  16. for ($i = 0; $i < count($blacklist); $i++) {
  17.   $blacklist[$i]= str_replace('*', '',$blacklist[$i]);
  18. }
  19. array_pop($blacklist);
  20. $arr = array_shift($result);
  21. $patterns= array();
  22. for ($i = 0; $i < count($arr); $i++) {
  23.   $patterns[]= "/$arr[$i]/";
  24. }
  25.  
  26. for ($i = 0; $i < count($arr); $i++) {
  27.   for ($j = 0; $j < count($blacklist); $j++) {
  28.     if(strpos($arr[$i], $blacklist[$j]) !=0 || strpos($arr[$i], $blacklist[$j])===0){
  29.         $arr[$i]= str_repeat('*', strlen($arr[$i]));
  30.     }
  31.   }
  32. }
  33. //var_dump($arr);
  34. for ($i = 0; $i < count($arr); $i++) {
  35.   if(!(strpos($arr[$i], '*')===0)){
  36.     $arr[$i]= "<a href=\"mailto:$arr[$i]\">$arr[$i]</a>";
  37.   }
  38. }
  39. //var_dump($arr);
  40. for ($i = 0; $i < count($arr); $i++) {
  41.  $text= preg_replace($patterns[$i], $arr[$i], $text);
  42. }
  43. $text = "<p>".$text."</p>";
  44. echo $text;
  45. //var_dump($text);
  46.  
  47. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement