Posted By

kossmoss on 03/30/09


php replace regexp links redirecting

Versions (?)

Replace all the links except local - For redirecting

 / Published in: PHP

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

  1. $host = str_replace('.', '\.', '');
  2. return preg_replace('/href=["|\']?(http:\/\/(?!'.$host.')([^"\']*))["|\']?/ui', "href=\"/go.php?url=$1\" title=\"$1\" target=\"_blank\"", $text);

Report this snippet  

You need to login to post a comment.