デモ

ソース

define('GOOGLE_TRENDS_API', 'http://www.google.co.jp/m/services/trends/get');

$trendsString = file_get_contents(GOOGLE_TRENDS_API);
preg_match_all('/<snippet src=\"(.+)\">/',$trendsString,$match);
if ($match) {
        $snippetUrlList = $match[1];
}
$trendsXml    = new SimpleXMLElement($trendsString);
$trendsList   = get_object_vars($trendsXml);
?>

<div class="well">
<ul class="pull-right unstyled">
<li><h5><?php echo date('Y年m月d日 H時i分s秒更新',strtotime($trendsList['update'])); ?></h5></li>
</ul>
<br />
<?php foreach($trendsList['item'] as $no => $trendData): ?>
<?php $trendData   = get_object_vars($trendData);?>
<?php $searchQuery = get_object_vars($trendData['landing_page']);?>
<div>
<h4 id="title"><?php echo htmlspecialchars($trendData['rank'],ENT_QUOTES); ?>. <a href="<?php echo htmlspecialchars($searchQuery['@attributes']['url'],ENT_QUOTES); ?>"><?php echo htmlspecialchars($trendData['query'],ENT_QUOTES); ?></a><?php if (isset($trendData['prev_rank'])) echo '(前回' . htmlspecialchars($trendData['rank'],ENT_QUOTES) . '位)'; ?></h4>
<blockquote><?php echo htmlspecialchars($trendData['snippet'],ENT_QUOTES); ?> <a href="<?php echo htmlspecialchars($snippetUrlList[$no],ENT_QUOTES); ?>" target="_blank">続きを読む<i class="icon-share"></i></a></blockquote>
</div>
<?php endforeach; ?>


  • google trends
  • ランキング
  • xmlパーサー