C
cuisi
Iota
SEO
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;$isaveHTML();
$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;
}
<?php echo getFollowers("cuisi")." followers"; ?>
buf muchas gracias 😀!
te iba a preguntar, en SMF hay un modulo que los aportes que hagas se postean automaticamente en twitter. Sabes algo para hacer esto en wordpress?
Saludos!
Gracias por el aporte amigo!!! ahora lo pondré en mi blog personal =)
Como se pondria en una web propia en php??
Supongo que metiendo el código en un fichero .php, luego importarlo en donde se va a utilizar y hacer la llamada a la función pasándole el parámetro a la misma, en este caso el User de Twitter.
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;
}
<script type="text/javascript" language="javascript" src="http://twittercounter.com/widget/index.php?username=danielmd"></script>
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;
}
<?php
include ('twitterfollow.php');
//Sustituir el "cuisi" por tu usuario de twitter y el texto seguido de el por lo que quieras que aparezca despues del numero de followers
echo getFollowers("cuisi")." followers";
?>
buf muchas gracias 😀!
te iba a preguntar, en SMF hay un modulo que los aportes que hagas se postean automaticamente en twitter. Sabes algo para hacer esto en wordpress?
Saludos!
mUy buenoo lo implementare en mi blogen cualquier caso el que sea correcto para implementarlo en php sería algo asi:
Crear twitterfollow.php con el siguiente codigo:
PHP: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; }
En la pag que lo quieras hacer hacer un include junto con el code:
Ejemplo en alguna parte del index.php:
PHP:<?php include ('twitterfollow.php'); //Sustituir el "cuisi" por tu usuario de twitter y el texto seguido de el por lo que quieras que aparezca despues del numero de followers echo getFollowers("cuisi")." followers"; ?>
En teoría debería funcionar si no se me escapa algo xD estoy más oxidado en php de lo que pensaba
Utilizamos cookies y tecnologías similares para los siguientes fines:
¿Aceptas las cookies y estas tecnologías?
Utilizamos cookies y tecnologías similares para los siguientes fines:
¿Aceptas las cookies y estas tecnologías?