Created
September 8, 2017 11:16
-
-
Save michelmelo/461d973db0f5d5a2ac2033bd92058dfe to your computer and use it in GitHub Desktop.
convert media_id for url
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 | |
function instagram_id_to_url($instagram_id){ | |
$url_prefix = "https://www.instagram.com/p/"; | |
$parts = explode('_', $instagram_id); | |
$instagram_id = $parts[0]; | |
$userid = $parts[1]; | |
$alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'; | |
while($instagram_id > 0) { | |
$remainder = $instagram_id % 64; | |
$instagram_id = ($instagram_id-$remainder) / 64; | |
$url_suffix = $alphabet{$remainder} . $url_suffix; | |
}; | |
return $url_prefix.$url_suffix; | |
} | |
$insta_id = "1596473034378028188_5929846787"; | |
$t = instagram_id_to_url($insta_id); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment