Created
October 7, 2014 02:57
-
-
Save mgng/470cb69c77214c2169dc to your computer and use it in GitHub Desktop.
twitter user_id <=> screen_name convert
This file contains hidden or 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 | |
$user_id = "5168731"; | |
$screen_name = "mugng"; | |
var_dump( | |
u2s( "5168731" ), // string(5) "mugng" | |
s2u( "mugng" ) // string(7) "5168731" | |
); | |
/** | |
* user_id 2 screen_name | |
* @param string $user_id | |
* @return string | |
*/ | |
function u2s( $user_id ) { | |
preg_match( "/class=\"nickname\">@(.+?)</uis", file_get_contents("https://twitter.com/intent/user?user_id={$user_id}"), $m ); | |
return isset( $m[1] ) ? $m[1] : null; | |
} | |
/** | |
* screen_name 2 user_id | |
* @param string $screen_name | |
* @return string | |
*/ | |
function s2u( $screen_name ) { | |
preg_match( "/content=\"twitter\:\/\/user\?id=(.+?)\"/uis", file_get_contents("https://twitter.com/intent/user?screen_name={$screen_name}"), $m ); | |
return isset( $m[1] ) ? $m[1] : null; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment