Skip to content

Instantly share code, notes, and snippets.

@morgyface
Created April 21, 2021 15:09
Show Gist options
  • Save morgyface/a53a8c9a677a4f0135e40c208cf1a15e to your computer and use it in GitHub Desktop.
Save morgyface/a53a8c9a677a4f0135e40c208cf1a15e to your computer and use it in GitHub Desktop.
PHP | Get handle from URL
<?php
/**
* Takes a complete URL and returns the user handle
* created for Instagram but also likely to work for other social channels
**/
function get_handle( $url ) {
$url = rtrim( $url, '/' );
$parse = parse_url( $url );
$path = $parse['path'];
$path = ltrim( $path, '/' );
return '@' . $path;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment