Skip to content

Instantly share code, notes, and snippets.

@HansF
Created December 22, 2010 17:03
Show Gist options
  • Save HansF/751762 to your computer and use it in GitHub Desktop.
Save HansF/751762 to your computer and use it in GitHub Desktop.
Input from macs.php, output linked profile images. example: http://fanatic.be/twit/
<?php
$url = "http://0x20.be/pam/macs";
if ($fp = fopen($url, 'r')) {
$output = '';
while ($line = fgets($fp, 1024)) {
$content .= $line;
}
$Twitternames = parseContent ($content);
if (is_array($Twitternames)) $output = generateHtml ($Twitternames);
echo $output;
}else{
echo "FAIL";
}
function parseContent ($content){
$twitternames = TwitterNamesFromString($content);
return $twitternames;
}
function TwitterNamesFromString($content){
$content = str_replace('"','',trim ($content, '[]'));
$macs = explode(",",$content);
while ($mac = array_pop($macs)){
if (stristr($mac,"@")){
$out[] = trim (trim ($mac, '"')," ");
}
}
return $out;
}
function generateHtml ($twitternames){
$output = "";
foreach ($twitternames as $twittername){
$xml ="http://api.twitter.com/1/users/show/$twittername.xml";
$xml = simplexml_load_file($xml) or die("feed not loading");
$imgurl = $xml->profile_image_url ;
$name = $xml->name ;
$screen_name = $xml->screen_name ;
$output .= "<a href ='http://twitter.com/$screen_name' title='$name'><img src='$imgurl' border='0'></a>";
}
return $output;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment