Created
February 19, 2012 22:31
-
-
Save NinjaPress/1866233 to your computer and use it in GitHub Desktop.
Exibindo total de seguidores do Twitter no Wordpress
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
function string_getInsertedString($long_string,$short_string,$is_html=false){ | |
if($short_string>=strlen($long_string))return false; | |
$insertion_length=strlen($long_string)-strlen($short_string); | |
for($i=0;$i<strlen($short_string);++$i){ | |
if($long_string[$i]!=$short_string[$i])break; | |
} | |
$inserted_string=substr($long_string,$i,$insertion_length); | |
if($is_html && $inserted_string[$insertion_length-1]=='<'){ | |
$inserted_string='<'.substr($inserted_string,0,$insertion_length-1); | |
} | |
return $inserted_string; | |
} | |
function DOMElement_getOuterHTML($document,$element){ | |
$html=$document->saveHTML(); | |
$element->parentNode->removeChild($element); | |
$html2=$document->saveHTML(); | |
return string_getInsertedString($html,$html2,true); | |
} | |
function getFollowers($username){ | |
$x = file_get_contents("http://twitter.com/".$username); | |
$doc = new DomDocument; | |
@$doc->loadHTML($x); | |
$ele = $doc->getElementById('follower_count'); | |
$innerHTML=preg_replace('/^<[^>]*>(.*)<[^>]*>$/',"\\1",DOMElement_getOuterHTML($doc,$ele)); | |
return $innerHTML; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Para exibir, basta abrir a página do tema onde quiser exibir o número de seguidores do Twitter e colar o código abaixo: