<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>A colourful bubble? &#187; PHP</title>
	<atom:link href="http://www.paopao.name/category/programme/php-programme/feed" rel="self" type="application/rss+xml" />
	<link>http://www.paopao.name</link>
	<description>生活 读书 新知</description>
	<lastBuildDate>Wed, 20 May 2009 02:22:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>打造自己的奥运奖牌榜</title>
		<link>http://www.paopao.name/life/sports/create-their-own-olympic-medal-count.html</link>
		<comments>http://www.paopao.name/life/sports/create-their-own-olympic-medal-count.html#comments</comments>
		<pubDate>Sat, 09 Aug 2008 16:10:13 +0000</pubDate>
		<dc:creator>paopao</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[体育]]></category>
		<category><![CDATA[奖牌榜]]></category>
		<category><![CDATA[奥运会]]></category>

		<guid isPermaLink="false">http://www.paopao.name/sports/create-their-own-olympic-medal-count.html</guid>
		<description><![CDATA[今天是奥运第一天，决出了7块金牌，7块银牌，9块铜牌。相信大家对奖牌榜都是很关注的，一般我是看新浪体育的奖牌榜的。不过为了把奖牌榜转载到BBS上，想要弄一个ASCII版的。我是个懒人，... ]]></description>
			<content:encoded><![CDATA[<p>今天是奥运第一天，决出了7块金牌，7块银牌，9块铜牌。相信大家对奖牌榜都是很关注的，一般我是看新浪体育的奖牌榜的。不过为了把奖牌榜转载到BBS上，想要弄一个ASCII版的。我是个懒人，不想每次更新奖牌榜的时候都重新手动做一遍，就用php写了个类，主要是从新浪体育抓取奖牌榜数据，然后输出成ASCII的格式。</p>
<pre class="brush: php;">
class MedalBoard {
	public $sourceURL, $status, $data, $countrycount;

	public function __construct() {
		$sourceURL = 'http://match.2008.sina.com.cn/bj2008/all_medal.php';
		if( $doc = file_get_contents($sourceURL) ){
			$posa = strpos($doc, '&lt;!-- Status begin --&gt;');
			$posb = strpos($doc, '&lt;!-- Status end --&gt;');
			$posc = strpos($doc, '&lt;!-- 数据 begin --&gt;');
			$posd = strpos($doc, '&lt;!-- 数据 end --&gt;');
			$statuspart = substr($doc, $posa, $posb - $posa);
			$datapart = substr($doc, $posc, $posd - $posc);
			if(!preg_match(&quot;/&lt;h1&gt;(.*)&lt;/h1&gt;[^&lt;]*&lt;span[^&gt;]*&gt;([^&lt;]*)&lt;/span&gt;.*[^&lt;]*&lt;label&gt;&lt;img[^&gt;]*&gt; ([^&lt;]*)&lt;/label&gt;[^&lt;]*&lt;label&gt;&lt;img[^&gt;]*&gt; ([^&lt;]*)&lt;/label&gt;[^&lt;]*&lt;label&gt;&lt;img[^&gt;]*&gt; ([^&lt;]*)&lt;/label&gt;/i&quot;, $statuspart, $this-&gt;status))
				$this-&gt;status = false;
			$this-&gt;countrycount = preg_match_all(&quot;/&lt;tr&gt;[^&lt;]*&lt;td&gt;(d*)&lt;/td&gt;[^&lt;]*&lt;td align.*d&quot;&gt;(.*)&lt;/a&gt;&lt;/td&gt;[^&lt;]*&lt;td&gt;(d*)&lt;/td&gt;[^&lt;]*&lt;td&gt;(d*)&lt;/td&gt;[^&lt;]*&lt;td&gt;(d*)&lt;/td&gt;[^&lt;]*&lt;td&gt;(d*)&lt;/td&gt;[^&lt;]*&lt;!--	&lt;td&gt;d*&lt;[^&lt;]*&lt;/tr&gt;/i&quot;, $datapart, $this-&gt;data, PREG_SET_ORDER);
		} else
			echo &quot;Get content: '&quot;.$sourceURL.&quot;' error!rn&quot;;
	}

	public function ascii() {
		$result =&quot;                 [1;37m2008北京奥运会 &quot;.$this-&gt;status[1].&quot;[0mnn&quot;;
		$result .=&quot;                        [1;37m&quot;.$this-&gt;status[2].&quot;[0mnn&quot;;
		$result .= &quot;           [1m排名[0m  [1m国家/地区   [0m [1;33m金牌[0m  [1;37m银牌[0m  [1;31m铜牌[0m  [1;35m总数[0mn&quot;;
		foreach($this-&gt;data as $items) {
			$result .= &quot;           &quot;;
			if(($items[2] == '中国') || ($items[2] == '中国香港') || ($items[2] == '中华台北')) {
				$result .= sprintf(&quot;[1;32m%-6s[0m&quot;,$items[1]);
				$result .= sprintf(&quot;[1;32m%-13s[0m&quot;,$items[2]);
			} else {
				$result .= sprintf(&quot;[1m%-6s[0m&quot;,$items[1]);
				$result .= sprintf(&quot;[1m%-13s[0m&quot;,$items[2]);
			}
			$result .= sprintf(&quot;[1;33m%-6s[0m&quot;,$items[3]);
			$result .= sprintf(&quot;[1;37m%-6s[0m&quot;,$items[4]);
			$result .= sprintf(&quot;[1;31m%-6s[0m&quot;,$items[5]);
			$result .= sprintf(&quot;[1;35m%-3s[0m&quot;,$items[6]);
			$result .= &quot;n&quot;;
		}
		return $result;
	}
}
</pre>
<p>如果你不喜欢网上看到的奖牌榜的外观，也可以用这个类来做一个自己的奖牌榜，比如弄一个和自己blog色调比较搭配的奖牌榜摆在侧边栏，只要加一个不同的输出格式的函数就行了，不过我是懒得弄了，想要自己做的朋友可以随意拿去用 ^_^</p>
<p></label></label></label></h1>
<img src="http://www.paopao.name/?ak_action=api_record_view&id=108&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.paopao.name/life/sports/create-their-own-olympic-medal-count.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
