function isexternal($url) {
  $components = parse_url($url);
  if ( empty($components['host']) ) return false;  // we will treat url like '/relative.php' as relative
  if ( strcasecmp($components['host'], '') === 0 ) return false; // url host looks exactly like the local host
  return strrpos(strtolower($components['host']), '') !== strlen($components['host']) - strlen(''); // check if the url host is a subdomain
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter