Last active
June 27, 2016 09:44
-
-
Save hatsumatsu/805db5bd6e4f5a4b744dc2e677330674 to your computer and use it in GitHub Desktop.
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
/** | |
* Extract the twitter user name from a twitter URL | |
* @param [type] $user_name [description] | |
* @return [type] [description] | |
*/ | |
public static function extract_username_from_url( $user_name ) { | |
// remove https://twitter.com/ | |
$user_name = str_replace( 'https://twitter.com/', '', $user_name ); | |
$user_name = str_replace( 'https://www.twitter.com/', '', $user_name ); | |
// remove http://twitter.com/ | |
$user_name = str_replace( 'http://twitter.com/', '', $user_name ); | |
$user_name = str_replace( 'http://www.twitter.com/', '', $user_name ); | |
// without protocol | |
$user_name = str_replace( 'twitter.com/', '', $user_name ); | |
$user_name = str_replace( 'www.twitter.com/', '', $user_name ); | |
// remove '@' | |
$user_name = str_replace( '@', '', $user_name ); | |
// remove '/'' | |
$user_name = str_replace( '/', '', $user_name ); | |
return $user_name; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment