php 读取 sogourank 与 ChinaRank信息
<?php function sogouRank($domain) { $rank = ''; $pr = 0; $content = file_get_contents('http://www.sogou.com/web?query=' . $domain); if (preg_match("/<\/span>([0-9]{1,})<\/dd>/", $content, $matches)) { $pr = intval($matches[1]); $width = ceil(65 * $pr / 100); $rank = '<img src="./images/sg_left.gif" width="2" height="11" /><img src="./images/sg_left_img.gif" width="' . $width . '" height="11" /><img src="./images/sg_right_img.gif" width="' . (65 - $width) . '" height="11" /><img src="./images/sg_right.gif" width="2" height="11" />'; } $rank = '<a href="http://www.sogou.com/web?query=link%3A' . $domain . '" target="_blank" title="搜狗Rank:' . $pr . '">' . $rank . '</a> ' . $pr; return $rank; } function ChinaRank($domain) { $rank = ''; $content = file_get_contents('http://www.chinarank.org.cn/detail/Info.do?url=' . $domain); if (preg_match("/<strong>排名<\/strong>(.*)<\/tr>/", $content, $matches)) { $p = trim(str_replace('</td>', '', $matches[1])); $p = explode("<td>", $p); if (isset($p[1])) $rank.= ' 今日:' . $p[1]; if (isset($p[2])) $rank.= ' 本周:' . $p[2]; if (isset($p[3])) $rank.= ' 三月:' . $p[3]; } $rank = '<a href="http://www.chinarank.org.cn/detail/Info.do?url=' . $domain . '" target="_blank">' . $rank . '</a>'; return $rank; }
本文地址:http://www.phprm.com/code/a7d9d81156521e07b4fb3be5dd1767c6.html
转载随意,但请附上文章地址:-)