Skip to content

Instantly share code, notes, and snippets.

@thesadoo
Created July 21, 2017 19:34
Show Gist options
  • Save thesadoo/0da594711d2784ce4ab18e36255aacc6 to your computer and use it in GitHub Desktop.
Save thesadoo/0da594711d2784ce4ab18e36255aacc6 to your computer and use it in GitHub Desktop.
Get user's Telegram avatar with a simple function using their Telegram usernames
<?php
function getTelegramAvatar($username='')
{
$username = $username;
$username = str_replace('@', '', $username);
$baseURL = 'https://telegram.me/';
$pageURL = $baseURL . $username;
$source = file_get_contents($pageURL);
$dom_obj = new DOMDocument();
$dom_obj->loadHTML($source);
$avatar = false;
foreach($dom_obj->getElementsByTagName('meta') as $meta) {
if($meta->getAttribute('property')=='og:image'){
$avatar = $meta->getAttribute('content');
}
}
return $avatar;
}
echo getTelegramAvatar('sadooam');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment