Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function removeUrl($string='', $replace_with='URL HIDDEN', $allowed_domains=null){
- $string = str_replace('....', '.', $string);
- $string = str_replace('...', '.', $string);
- $string = str_replace('..', '.', $string);
- $string = preg_replace('/(\d)\.([a-z]{2,3})/', '$1. $2', $string);
- $string = preg_replace_callback('@((https?://)?([-\w]+\.[-\w\.][^\/0-9\-]+)+\w(:\d+)?(/([-\w/_\.]*(\?\S+)?)?)*)@', function($match) use($replace_with, $allowed_domains){
- // Allowed domains
- if(strpos($match[0], '...') !== false){
- return $match[0];
- }
- // Return replaced string
- return ' ['.strtoupper($replace_with).'] ';
- }, $string);
- return $string;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement