Skip to content

Instantly share code, notes, and snippets.

@jazzsequence
Last active December 14, 2015 00:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jazzsequence/5000545 to your computer and use it in GitHub Desktop.
Save jazzsequence/5000545 to your computer and use it in GitHub Desktop.
Gets a specified url, spits it back out as just a domain
function get_source( $url ) {
$source = parse_url( $url );
$article_source = str_replace( array('www.','www1.','blogs.'), '', $source["host"]); // add whatever prefixes you want here
echo $article_source;
}
// to run this function do this:
$url = 'http://www.mydomain.com/some/crazy/path/';
get_source( $url ); // returns mydomain.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment