enter site to get a tag cloud for:
url
the php source that makes this page run:
<?php # cached_fopen_url() -- see http://www.php.net/manual/tw/function.fopen.php#49478 require_once '/nfsn/content/oncemore/htdocs/mod/cached.inc'; # xml2array -- see http://viebrock.ca/code/21/php-snippet-xml2array # php 5+ has built-in xml functions which do more or less the same thing require_once '/nfsn/content/oncemore/htdocs/mod/xml2array.inc'; $appid = "yahooAPIid"; # Your yahoo API id $method = "http://api.search.yahoo.com/MyWebService/V1/tagSearch"; $url = $_GET[url]; $script = $_SERVER['PHP_SELF']; if ($url) { $handle = cached_fopen_url("$method?url=$url&appid=$appid&sort=popularity&results=50", "rb"); $content = ''; // here you receive content of page while(!feof($handle)) { $content .= fread($handle,4096); } fclose($handle); $objXML = new xml2Array(); $arrOutput = $objXML->parse($content); /* echo '
'; print_r($arrOutput); echo '
'; */ $tags = array(); $freqs = array(); $i = 0; foreach($arrOutput[0][children] as $thisTag) { $tagName = $thisTag[children][0][tagData]; $tagFreq = $thisTag[children][1][tagData]; $tags[$i] = $tagName; $freqs[$i] = $tagFreq; $i++; } array_multisort($tags, $freqs); echo "
tag cloud for
$url
:
\n"; if (count($freqs)) { $avgFreq = round( array_sum($freqs) / count($freqs) ); $i = 0; echo "
"; foreach($tags as $thisTag) { $tagFreq = round($freqs[$i]/$avgFreq)+10; echo "
"; echo '
' . $thisTag . "
\n"; $i++; } echo "
"; } else echo "no hits for this url."; } else { $url = 'http://'; } echo '
enter site to get a tag cloud for:
'; echo "
\n"; echo "
url
\n"; echo "
\n"; ?>