Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.65 KB | None | 0 0
  1. function removeUrl($string='', $replace_with='URL HIDDEN', $allowed_domains=null){
  2.     $string = str_replace('....', '.', $string);
  3.     $string = str_replace('...', '.', $string);
  4.     $string = str_replace('..', '.', $string);
  5.     $string = preg_replace('/(\d)\.([a-z]{2,3})/', '$1. $2', $string);
  6.     $string = preg_replace_callback('@((https?://)?([-\w]+\.[-\w\.][^\/0-9\-]+)+\w(:\d+)?(/([-\w/_\.]*(\?\S+)?)?)*)@', function($match) use($replace_with, $allowed_domains){
  7.         // Allowed domains
  8.         if(strpos($match[0], '...') !== false){
  9.             return $match[0];
  10.         }
  11.         // Return replaced string
  12.         return ' ['.strtoupper($replace_with).'] ';
  13.     }, $string);
  14.     return $string;
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement