Advertisement
Guest User

2nd problem

a guest
Aug 28th, 2014
361
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 [email protected] . Secondary email: [email protected] or at [email protected] OR [email protected]";
  6. $blacklist  = $_GET['blacklist'];
  7. //$blacklist = '*.bg
  8. //*.com
  9. //';
  10. $pattern = '/[0-9A-Za-z\_\+\-]+@[0-9A-Za-z\-]+\.[0-9A-Za-z\-\.]+/';
  11.  
  12. preg_match_all($pattern, $text, $result);
  13. $blacklist = preg_split('/[\n\r]+/', $blacklist);
  14.  
  15. for ($i = 0; $i < count($blacklist); $i++) {
  16.   $blacklist[$i]= str_replace('*', '',$blacklist[$i]);
  17. }
  18. array_pop($blacklist);
  19. $arr = array_shift($result);
  20. $patterns= array();
  21. for ($i = 0; $i < count($arr); $i++) {
  22.   $patterns[]= "/$arr[$i]/";
  23. }
  24.  
  25. for ($i = 0; $i < count($arr); $i++) {
  26.   for ($j = 0; $j < count($blacklist); $j++) {
  27.     if(strpos($arr[$i], $blacklist[$j]) !=0 || strpos($arr[$i], $blacklist[$j])===0){
  28.         $arr[$i]= str_repeat('*', strlen($arr[$i]));
  29.     }
  30.   }
  31. }
  32. //var_dump($arr);
  33. for ($i = 0; $i < count($arr); $i++) {
  34.   if(!(strpos($arr[$i], '*')===0)){
  35.     $arr[$i]= "<a href=\"mailto:$arr[$i]\">$arr[$i]</a>";
  36.   }
  37. }
  38. //var_dump($arr);
  39. for ($i = 0; $i < count($arr); $i++) {
  40.  $text= preg_replace($patterns[$i], $arr[$i], $text);
  41. }
  42. $text = "<p>".$text."</p>";
  43. echo $text;
  44. //var_dump($text);
  45.  
  46. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement