Created
April 21, 2021 15:09
-
-
Save morgyface/a53a8c9a677a4f0135e40c208cf1a15e to your computer and use it in GitHub Desktop.
PHP | Get handle from URL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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