Replace all the links except local - For redirecting


/ Published in: PHP
Save to your folder(s)

You can get hostname from script environment - getenv("HTTP_HOST")
(?!'.$host.') matches URLs always except local links


Copy this code and paste it in your HTML
  1. $host = str_replace('.', '\.', 'your.host.com');
  2. return preg_replace('/href=["|\']?(http:\/\/(?!'.$host.')([^"\']*))["|\']?/ui', "href=\"/go.php?url=$1\" title=\"$1\" target=\"_blank\"", $text);

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.