<?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>憂藍夢境‧部落格 &#187; 程式筆記</title>
	<atom:link href="http://blog.linym.net/archives/category/program/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.linym.net</link>
	<description>我的學習心得、筆記</description>
	<lastBuildDate>Fri, 09 Dec 2011 12:33:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>使用 C# 呼叫 MATLAB Function</title>
		<link>http://blog.linym.net/archives/564</link>
		<comments>http://blog.linym.net/archives/564#comments</comments>
		<pubDate>Thu, 10 Sep 2009 07:49:21 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[程式筆記]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[MATLAB]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.linym.net/?p=564</guid>
		<description><![CDATA[最近在寫一些演算法的程式，經常要在一堆程式和檔案切換來切換去的，跑完數據還要開 MATLAB 畫圖，一直重複這些動作實在是很麻煩，所以把它寫成 Windows Form 用滑鼠點一點就 OK 了，其中繪圖部份就要利用 C# 去 call MATLAB 來作，查了許多資料，發現有很多種方法，但比較簡單方便的應該是用 MATLAB Builder NE for .NET 將 MATLAB 程式編譯成 .NET 可執行的元件。 1. 首先準備好你要 compiler 的 M-file，測試的 M-file 如下(由檔案讀取 x, y 數據曲線圖)： function rmse(file) data = load(file); x = data(:,1); y = data(:,2); plot(x,y,&#039;LineWidth&#039;,1); xlabel(&#039;Iteration&#039;); ylabel(&#039;RMS error&#039;); 2. 開啟 MATLAB 並在 command windows 輸入：deploytool [...]]]></description>
			<content:encoded><![CDATA[<p>最近在寫一些演算法的程式，經常要在一堆程式和檔案切換來切換去的，跑完數據還要開 MATLAB 畫圖，一直重複這些動作實在是很麻煩，所以把它寫成 Windows Form 用滑鼠點一點就 OK 了，其中繪圖部份就要利用 C# 去 call MATLAB 來作，查了許多資料，發現有很多種方法，但比較簡單方便的應該是用 <a href="http://www.mathworks.com/products/netbuilder/" target="_blank">MATLAB Builder NE for .NET</a> 將 MATLAB 程式編譯成 .NET 可執行的元件。</p>
<p>1. 首先準備好你要 compiler 的 M-file，測試的 M-file 如下(由檔案讀取 x, y 數據曲線圖)：</p>
<pre title="code" class="cpp">

function rmse(file)

data = load(file);
x = data(:,1);
y = data(:,2);

plot(x,y,&#039;LineWidth&#039;,1);

xlabel(&#039;Iteration&#039;);
ylabel(&#039;RMS error&#039;);
</pre>
<p>2. 開啟 MATLAB 並在 command windows 輸入：<strong>deploytool</strong><br />
    新建一個 project，名稱為 rmse。<br />
    <a href="http://blog.linym.net/wp-content/uploads/2009/09/01.JPG"><img src="http://blog.linym.net/wp-content/uploads/2009/09/01.JPG" alt="New Project" title="New Project" width="646" height="451" class="alignnone size-full wp-image-567" /></a><br />
    選擇 .NET component<br />
    <a href="http://blog.linym.net/wp-content/uploads/2009/09/2.JPG"><img src="http://blog.linym.net/wp-content/uploads/2009/09/2.JPG" alt=".NET component" title=".NET component" width="510" height="510" class="alignnone size-full wp-image-571" /></a><br />
    將 M-file 加入，然後按<strong> Build the project</strong>，編譯完成會產生 rmse.dll<br />
<a href="http://blog.linym.net/wp-content/uploads/2009/09/3.JPG"><img src="http://blog.linym.net/wp-content/uploads/2009/09/3.JPG" alt="Add file" title="Add file" width="646" height="451" class="alignnone size-full wp-image-574" /></a></p>
<p>3. 將 .dll 加入 Visual Studio 參考(Reference)<br />
   在方案總管右鍵選「加入參考」>「瀏覽」，將剛剛編譯完成的 .dll 以及 MATLAB 安裝目錄底下的 toolbox\dotnetbuilder\bin\win32\v2.0\MWArray.dll 加入。</p>
<p>4. 加入 Namespace<br />
using MathWorks.MATLAB.NET.Arrays;<br />
using rmse;</p>
<p>5. 使用方式<br />
    Rmse demo = new Rmse();<br />
    MWArray fileName = @"rmse.txt";<br />
    demo.rmse(fileName);</p>
<p>※ <a href='http://blog.linym.net/wp-content/uploads/2009/09/CSharp_Matlab.rar'>demo 範例原始碼下載</a></p>
<p>※ 如果想在沒安裝 MATLAB 的電腦上執行，需安裝 MATLAB Compiler Runtime (MCR)，檔案在安裝目錄的 toolbox\compiler\deploy\win32\MCRInstaller.exe，大小約 150MB</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/564/feed</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Windows PPPoE 自動重撥 Script</title>
		<link>http://blog.linym.net/archives/522</link>
		<comments>http://blog.linym.net/archives/522#comments</comments>
		<pubDate>Sat, 25 Jul 2009 10:51:09 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[程式筆記]]></category>
		<category><![CDATA[系統筆記]]></category>
		<category><![CDATA[adsl]]></category>
		<category><![CDATA[pppoe]]></category>
		<category><![CDATA[WSH]]></category>
		<category><![CDATA[自動連線]]></category>

		<guid isPermaLink="false">http://blog.linym.net/?p=522</guid>
		<description><![CDATA[隨著 ADSL 及經濟型光纖網路的普及，有許多人都會在自家架設 server 主機，但如果沒有用分享器而是直接透過 PPPoE 撥接上網的，就很怕網路突然斷線(如忘記繳錢被停掉)，雖然說 Windows 內建的連線程式有一個「斷線後重新撥號」的選項，但其實並不好用。比較保險的作法是系統定期檢查對外連線的狀況(ping)，一旦發現斷線就自動重新連線。 在網路上可以找到很多這種作法的 Linux 版本，如「Debian Linux: ADSL PPPoE 自動重撥 Script」，但相對 Windows 的討論卻很少，所以就自己寫了一個重撥的 WSH(Windows Script Host)，搭配工作排程就可以達到目的。 ※ 本方法適用於 XP 以後之 Windows。 Step 1：將下列程式存為 repppoe.vbs，修改連線資訊並放置在安全的地方 DIALNAME = &#34;寬頻連線&#34; &#039;連線名稱 DIALUSER = &#34;12345678@ip.hinet.net&#34; &#039;連線帳號 DIALPASS = &#34;xxxxxxxx&#34; &#039;連線密碼 Set WshShell = CreateObject(&#34;WScript.Shell&#34;) RetCode = WshShell.Run(&#34;ping www.hinet.net&#34;, 0, true) If RetCode &#60;&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>隨著 ADSL 及經濟型光纖網路的普及，有許多人都會在自家架設 server 主機，但如果沒有用分享器而是直接透過 PPPoE 撥接上網的，就很怕網路突然斷線(如忘記繳錢被停掉)，雖然說 Windows 內建的連線程式有一個「斷線後重新撥號」的選項，但其實並不好用。比較保險的作法是系統定期檢查對外連線的狀況(ping)，一旦發現斷線就自動重新連線。</p>
<p>在網路上可以找到很多這種作法的 Linux 版本，如「<a href="http://plog.longwin.com.tw/programming/2007/08/24/adsl_repppoe_script_2007" target="_blank">Debian Linux: ADSL PPPoE 自動重撥 Script</a>」，但相對 Windows 的討論卻很少，所以就自己寫了一個重撥的 WSH(Windows Script Host)，搭配工作排程就可以達到目的。<br />
<span style="color:red">※ 本方法適用於 XP 以後之 Windows。</span></p>
<p><strong>Step 1：將下列程式存為 <span style="color:blue">repppoe.vbs</span>，修改連線資訊並放置在安全的地方</strong></p>
<pre title="code" class="vb">

DIALNAME = &quot;寬頻連線&quot;              &#039;連線名稱
DIALUSER = &quot;12345678@ip.hinet.net&quot; &#039;連線帳號
DIALPASS = &quot;xxxxxxxx&quot;              &#039;連線密碼

Set WshShell = CreateObject(&quot;WScript.Shell&quot;)
RetCode = WshShell.Run(&quot;ping www.hinet.net&quot;, 0, true)
If RetCode &lt;&gt; 0 Then
	WshShell.Run &quot;rasdial &quot; &amp; DIALNAME &amp; &quot; /DISCONNECT&quot;, 0, true
	WScript.Sleep(3000)
	WshShell.Run &quot;rasdial &quot; &amp; DIALNAME &amp; &quot; &quot; &amp; DIALUSER &amp; &quot; &quot; &amp; DIALPASS, 0
End If
</pre>
<p><strong>Step 2：設定 Windows 工作排程。</strong>(控制台->排定的工作->新增排定的工作)</p>
<p><a href="http://blog.linym.net/wp-content/uploads/2009/07/1.JPG"><img src="http://blog.linym.net/wp-content/uploads/2009/07/1.JPG" alt="1" title="1" width="522" height="326" class="alignnone size-full wp-image-535" /></a><br />
‧選擇步驟 1 的 repppoe.vbs 檔案</p>
<p><a href="http://blog.linym.net/wp-content/uploads/2009/07/2.JPG"><img src="http://blog.linym.net/wp-content/uploads/2009/07/2.JPG" alt="2" title="2" width="522" height="326" class="alignnone size-full wp-image-538" /></a></p>
<p><a href="http://blog.linym.net/wp-content/uploads/2009/07/3.JPG"><img src="http://blog.linym.net/wp-content/uploads/2009/07/3.JPG" alt="3" title="3" width="522" height="326" class="alignnone size-full wp-image-539" /></a></p>
<p><a href="http://blog.linym.net/wp-content/uploads/2009/07/4.JPG"><img src="http://blog.linym.net/wp-content/uploads/2009/07/4.JPG" alt="4" title="4" width="522" height="326" class="alignnone size-full wp-image-541" /></a><br />
‧輸入具有 Administrator 權限的使用者及密碼</p>
<p><a href="http://blog.linym.net/wp-content/uploads/2009/07/5.JPG"><img src="http://blog.linym.net/wp-content/uploads/2009/07/5.JPG" alt="5" title="5" width="522" height="326" class="alignnone size-full wp-image-542" /></a></p>
<p><a href="http://blog.linym.net/wp-content/uploads/2009/07/6.JPG"><img src="http://blog.linym.net/wp-content/uploads/2009/07/6.JPG" alt="6" title="6" width="406" height="416" class="alignnone size-full wp-image-543" /></a></p>
<p><a href="http://blog.linym.net/wp-content/uploads/2009/07/7.JPG"><img src="http://blog.linym.net/wp-content/uploads/2009/07/7.JPG" alt="7" title="7" width="368" height="252" class="alignnone size-full wp-image-544" /></a><br />
‧表示每 30 分鐘檢查一次連線狀況，可依需求修改，然後收工。</p>
<p>※ 備註：<br />
之所以選擇 ping www.hinet.net 而不用 IP 是因為經實驗結果，若網卡有設定 Default gateway，則可能會因為 gateway response 影響連線判斷。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/522/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>jQuery Drag and Drop Demo</title>
		<link>http://blog.linym.net/archives/452</link>
		<comments>http://blog.linym.net/archives/452#comments</comments>
		<pubDate>Wed, 11 Mar 2009 15:54:47 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[程式筆記]]></category>
		<category><![CDATA[網頁設計]]></category>
		<category><![CDATA[Drag and Drop]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[UI]]></category>

		<guid isPermaLink="false">http://blog.linym.net/?p=452</guid>
		<description><![CDATA[Drag &#038; Drop(拖放) 效果若是應用得當可以讓 UI 操作更直覺簡單，目前最常見的大概就是對項目作排序，或是像購物車將物體從某區塊移到另一區塊。 網路上雖然有很多 Drag &#038; Drop 的範例，但有些過於複雜或是不夠完整，前陣子為了交作業嘗試用 jQuery+jQuery UI 做了一個簡單的 Demo，果然快速、簡潔、流暢，不得不再次向大家推薦 jQuery 啊！ Demo 網址：http://blog.linym.net/demo/jquery/jquery_DragDrop.html]]></description>
			<content:encoded><![CDATA[<p>Drag &#038; Drop(拖放) 效果若是應用得當可以讓 UI 操作更直覺簡單，目前最常見的大概就是對項目作排序，或是像購物車將物體從某區塊移到另一區塊。</p>
<p>網路上雖然有很多 Drag &#038; Drop 的範例，但有些過於複雜或是不夠完整，前陣子為了交作業嘗試用 jQuery+jQuery UI 做了一個簡單的 Demo，果然快速、簡潔、流暢，不得不再次向大家推薦 jQuery 啊！</p>
<p><strong>Demo 網址</strong>：<a href="http://blog.linym.net/demo/jquery/jquery_DragDrop.html" target="_blank">http://blog.linym.net/demo/jquery/jquery_DragDrop.html</a></p>
<p><a href="http://blog.linym.net/wp-content/uploads/2009/03/dragdrop.jpg"><img src="http://blog.linym.net/wp-content/uploads/2009/03/dragdrop.jpg" alt="dragdrop" title="dragdrop" width="701" height="589" class="alignnone size-full wp-image-460" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/452/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>修改 SyntaxHighlighter 符合 XHTML 驗證</title>
		<link>http://blog.linym.net/archives/415</link>
		<comments>http://blog.linym.net/archives/415#comments</comments>
		<pubDate>Thu, 08 Jan 2009 06:17:04 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[程式筆記]]></category>
		<category><![CDATA[網頁設計]]></category>
		<category><![CDATA[SyntaxHighlighter]]></category>
		<category><![CDATA[W3C]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://blog.linym.net/?p=415</guid>
		<description><![CDATA[本站顯示程式碼是用「SyntaxHighlighter」，有人將它寫成 WP plugin，使用上非常方便，不過 SyntaxHighlighter 預設的呼叫語法是用 &#60;pre name="code" class="html"&#62;......&#60;/pre&#62; 由於 W3C 規範中 pre tag 是沒有 name 屬性的，所以鐵定要跟驗證貼紙說 bye bye，如果真的很在意的話可以這樣修改： 1. 修改 syntaxhighlighter.php 找到 &#60;pre name="code" 改成 &#60;pre title="code" 2. 修改 files/shCore.js 找到 tags[i].getAttribute('name') 改成 tags[i].getAttribute('title') 以 title 替換 name 屬性，這樣就能通過驗證了。 參考文章：Google SyntaxHighlighter - workaround for XHTML validation issue]]></description>
			<content:encoded><![CDATA[<p>本站顯示程式碼是用「<a href="http://code.google.com/p/syntaxhighlighter/" target="_blank">SyntaxHighlighter</a>」，有人將它寫成 <a href="http://wordpress.org/extend/plugins/syntaxhighlighter/" target="_blank">WP plugin</a>，使用上非常方便，不過 SyntaxHighlighter 預設的呼叫語法是用</p>
<pre>&lt;pre <strong>name</strong>="code" class="html"&gt;......&lt;/pre&gt;</pre>
<p>由於 W3C 規範中 pre tag 是沒有 name 屬性的，所以鐵定要跟驗證貼紙說 bye bye，如果真的很在意的話可以這樣修改：</p>
<p><strong>1. 修改 syntaxhighlighter.php</strong></p>
<pre>
找到
&lt;pre name="code"
改成
&lt;pre <strong>title</strong>="code"
</pre>
<p><strong>2. 修改 files/shCore.js</strong></p>
<pre>
找到
tags[i].getAttribute('name')
改成
tags[i].getAttribute('<strong>title</strong>')
</pre>
<p>以 title 替換 name 屬性，這樣就能通過驗證了。</p>
<p>參考文章：<a href="http://aumlette.me.uk/weblog/google-syntaxhighlighter-workaround-for-xhtml-validation-issue/">Google SyntaxHighlighter - workaround for XHTML validation issue</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/415/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[WordPress] 在 IIS 使用固定網址(Permalink)</title>
		<link>http://blog.linym.net/archives/319</link>
		<comments>http://blog.linym.net/archives/319#comments</comments>
		<pubDate>Thu, 08 Jan 2009 03:42:20 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[Server]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[程式筆記]]></category>
		<category><![CDATA[系統筆記]]></category>
		<category><![CDATA[IIS]]></category>
		<category><![CDATA[mod_rewrite]]></category>
		<category><![CDATA[Permalinks]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[固定網址]]></category>

		<guid isPermaLink="false">http://blog.linym.net/?p=319</guid>
		<description><![CDATA[Apache 有個非常強大好用的 mod_rewrite 模組，可以實現 URL Rewriting，運用在網站或部落格對 SEO 會有幫助。WP 的固定網址也是這類的運用，一般架設在 Apache 不會有什麼問題，只要有啟用 mod_rewrite 就 OK，不過如果是裝在 IIS 上，那就會看到很醜的 /index.php/aaa/bbb/123 這樣的網址，本篇就是教大家如何讓 IIS 真正擁有 rewrite 的功能。 首先必須安裝 for IIS 的擴充，微軟有針對 IIS7 開發一套 URL Rewrite Module，不過 IIS6 就只能用別的，測試很多套最後選擇 ISAPI_Rewrite，因為它幾乎相容 .htaccess、mod_rewrite 語法，也比較穩定，ISAPI_Rewrite 有分要錢的 full 版和免費的 Lite 版，差異請看這篇，目前選 Lite 就夠用了。 Step 1 先設定 WordPress ，進入後台選擇想要的固定網址格式，如「/%year%/%monthnum%/%day%/%postname%.html」，記得把前面 index.php 拿掉。 Step 2 安裝好 ISAPI_Rewrite 3 [...]]]></description>
			<content:encoded><![CDATA[<p>Apache 有個非常強大好用的 mod_rewrite 模組，可以實現 URL Rewriting，運用在網站或部落格對 SEO 會有幫助。WP 的固定網址也是這類的運用，一般架設在 Apache 不會有什麼問題，只要有啟用 mod_rewrite 就 OK，不過如果是裝在 IIS 上，那就會看到很醜的 /<strong>index.php</strong>/aaa/bbb/123 這樣的網址，本篇就是教大家如何讓 IIS 真正擁有 rewrite 的功能。</p>
<p>首先必須安裝 for IIS 的擴充，微軟有針對 IIS7 開發一套 <a href="http://www.iis.net/downloads/default.aspx?tabid=34&#038;g=6&#038;i=1691" target="_blank">URL Rewrite Module</a>，不過 IIS6 就只能用別的，測試很多套最後選擇 <a href="http://www.helicontech.com/isapi_rewrite/" target="_blank">ISAPI_Rewrite</a>，因為它幾乎相容 .htaccess、mod_rewrite 語法，也比較穩定，ISAPI_Rewrite 有分要錢的 full 版和免費的 Lite 版，差異請看<a href="http://www.helicontech.com/isapi_rewrite/doc/litever.htm" target="_blank">這篇</a>，目前選 Lite 就夠用了。</p>
<p><strong>Step 1</strong><br />
先設定 WordPress ，進入後台選擇想要的固定網址格式，如「/%year%/%monthnum%/%day%/%postname%.html」，記得把前面 index.php 拿掉。<br />
<img src="http://blog.linym.net/wp-content/uploads/2009/01/e693b7e58f96.jpg" alt="固定網址" title="固定網址" width="624" height="324" class="alignnone size-full wp-image-330" /></p>
<p><strong>Step 2</strong><br />
安裝好 <a href="http://www.helicontech.com/download-isapi_rewrite3.htm" target="_blank">ISAPI_Rewrite 3 Lite</a>，編輯安裝目錄下的 httpd.conf 設定檔，內容範例：</p>
<pre>
# 假設WP網址為 http://aaa.domain.com/blog/
RewriteCond %{HTTP_HOST} ^aaa\.domain\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/blog/ /blog/index\.php [L]

# 假設WP網址為 http://bbb.domain.com
RewriteCond %{HTTP_HOST} ^bbb\.domain\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index\.php [L]
</pre>
<p><strong>Step 3</strong><br />
基本上完成前兩個動作固定網址就可以運作了，但是如果網址帶有中文就會發生 404 錯誤，原因可以參考<a href="http://www.zu14.cn/2008/12/13/wordpress_iis_cn/" target="_blank">這篇</a>，修改 wp-includes/classes.php</p>
<pre>
// 找到
$pathinfo = $_SERVER['PATH_INFO'];
// 改成
$pathinfo = mb_convert_encoding($_SERVER['PATH_INFO'], 'UTF-8', 'BIG5');

// 找到
$req_uri = $_SERVER['REQUEST_URI'];
// 改成
$req_uri = mb_convert_encoding($_SERVER['REQUEST_URI'], 'UTF-8', 'BIG5');
</pre>
<p>這樣就正常了。註：PHP 必須啟用 mbstring。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/319/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>IIS6+PHP5 (FastCGI) 安裝攻略</title>
		<link>http://blog.linym.net/archives/264</link>
		<comments>http://blog.linym.net/archives/264#comments</comments>
		<pubDate>Tue, 30 Sep 2008 03:01:08 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[系統筆記]]></category>
		<category><![CDATA[FastCGI]]></category>
		<category><![CDATA[IIS]]></category>
		<category><![CDATA[server 2003]]></category>

		<guid isPermaLink="false">http://blog.linym.net/?p=264</guid>
		<description><![CDATA[以往 PHP 的執行模式可分成 CGI 及 ISAPI 兩種，CGI 的 performance 是出名的慢，而 ISAPI 是較多人使用的，但是在 Windows 卻穩定性不佳，經常會導致整個 web server crash，所以微軟特別針對 IIS 開發了 FastCGI 模組(IIS7 已內建)，據說效能及穩定性都有大大改善。 安裝步驟： 1. 確認 IIS 已經裝好，然後下載 FastCGI Extension for IIS 6 並且安裝完成。 2. 到 PHP 官網下載新版 PHP5 壓縮檔，並且解壓縮(假設在 C:\PHP5)。 3. 將 C:\PHP5\php.ini-dist 改名為 php.ini，然後依需求編輯設定檔內容，範例： (後三行必要) include_path = &#34;.;C:\Inetpub\wwwroot&#34; extension_dir = &#34;C:\PHP5\ext&#34; extension=php_curl.dll extension=php_gd2.dll extension=php_mbstring.dll [...]]]></description>
			<content:encoded><![CDATA[<p>以往 PHP 的執行模式可分成 CGI 及 ISAPI 兩種，CGI 的 performance 是出名的慢，而 ISAPI 是較多人使用的，但是在 Windows 卻穩定性不佳，經常會導致整個 web server crash，所以微軟特別針對 IIS 開發了 FastCGI 模組(IIS7 已內建)，據說效能及穩定性都有大大改善。</p>
<p><strong>安裝步驟：</strong><br />
1. 確認 IIS 已經裝好，然後下載 <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=2d481579-9a7c-4632-b6e6-dee9097f9dc5&#038;displaylang=en" target="_blank">FastCGI Extension for IIS 6</a> 並且安裝完成。</p>
<p>2. 到 <a href="http://www.php.net/downloads.php" target="_blank">PHP 官網</a>下載新版 PHP5 壓縮檔，並且解壓縮(假設在 C:\PHP5)。</p>
<p>3. 將 C:\PHP5\php.ini-dist 改名為 php.ini，然後依需求編輯設定檔內容，範例：<br />
<strong>(後三行必要)</strong></p>
<pre>
include_path = &quot;.;C:\Inetpub\wwwroot&quot;
extension_dir = &quot;C:\PHP5\ext&quot;

extension=php_curl.dll
extension=php_gd2.dll
extension=php_mbstring.dll
extension=php_mcrypt.dll
extension=php_mysql.dll
extension=php_mysqli.dll
extension=php_openssl.dll
extension=php_zip.dll

date.timezone = "Asia/Taipei"

cgi.force_redirect = 0
cgi.fix_pathinfo=1
fastcgi.impersonate = 1;
</pre>
<p>4. 對 C:\PHP5 目錄增加 IIS_WPG 群組的讀取及執行權限。<br />
<strong>(沒加這個就會跑出 FastCGI Error)</strong><br />
<a href="http://blog.linym.net/wp-content/uploads/2008/09/01.jpg" target="_blank"><img src="http://blog.linym.net/wp-content/uploads/2008/09/01.jpg" alt="" title="增加權限" width="368" height="445" class="alignnone size-full wp-image-268" /></a></p>
<p>5. 加入系統環境變數 (讓 extension 及 php.ini 能順利被找到)。<br />
Path=C:\PHP5;<br />
PHPRC=C:\PHP5<br />
<a href="http://blog.linym.net/wp-content/uploads/2008/09/05.jpg" target="_blank"><img src="http://blog.linym.net/wp-content/uploads/2008/09/05.jpg" alt="" title="環境變數" width="384" height="393" class="alignnone size-full wp-image-253" /></a></p>
<p>6. 開啟 IIS 管理員，如下圖設定。<br />
<a href="http://blog.linym.net/wp-content/uploads/2008/09/02.jpg" target="_blank"><img src="http://blog.linym.net/wp-content/uploads/2008/09/02.jpg" alt="" title="IIS管理員" width="471" height="449" class="alignnone size-full wp-image-270" /></a></p>
<p>7. 增加預設首頁 index.php<br />
<a href="http://blog.linym.net/wp-content/uploads/2008/09/08.jpg" target="_blank"><img src="http://blog.linym.net/wp-content/uploads/2008/09/08.jpg" alt="" title="預設首頁" width="471" height="430" class="alignnone size-full wp-image-259" /></a></p>
<p>8. 檢查網頁服務延伸。<br />
(正常的話應該會有這一項，若沒有請自行加入 C:\WINDOWS\system32\inetsrv\fcgiext.dll)<br />
<a href="http://blog.linym.net/wp-content/uploads/2008/09/031.jpg"><img src="http://blog.linym.net/wp-content/uploads/2008/09/031.jpg" alt="" title="網頁服務延伸" width="500" height="352" class="alignnone size-full wp-image-272" /></a></p>
<p>9. 開始 > 執行 > cmd<br />
輸入四道指令(注意路徑)：<br />
cd C:\WINDOWS\system32\inetsrv</p>
<p>cscript fcgiconfig.js -add -section:&quot;PHP&quot; -extension:php -path:&quot;<strong>C:\PHP5\php-cgi.exe</strong>&quot;</p>
<p>cscript fcgiconfig.js -set -section:&quot;PHP&quot; -InstanceMaxRequests:10000</p>
<p>cscript fcgiconfig.js -set -section:&quot;PHP&quot; -EnvironmentVars:PHP_FCGI_MAX_REQUESTS:10000<br />
(視情況修改數值，InstanceMaxRequests 需小於等於 PHP_FCGI_MAX_REQUESTS)</p>
<p>10. 重新啟動 IIS 就 OK 囉，丟一個測試檔案到網站目錄看看吧！<br />
<a href="http://blog.linym.net/wp-content/uploads/2008/09/04.jpg" target="_blank"><img src="http://blog.linym.net/wp-content/uploads/2008/09/04.jpg" alt="" title="phpinfo" width="500" height="339" class="alignnone size-full wp-image-275" /></a></p>
<p><strong>※2009/03/19 補充：</strong><br />
   使用 FastCGI 執行 PHP 程式時，系統是以「NETWORK SERVICE」這個身份執行的，而一般靜態檔案則是以 IIS 預設的匿名身份「IUSR_MachineName」執行，所以如果安裝上發生問題，請特別注意這個權限配置。</p>
<p><strong>相關文章：</strong></p>
<ul>
<li><a href="http://learn.iis.net/page.aspx/247/using-fastcgi-to-host-php-applications-on-iis-60/">Using FastCGI to Host PHP Applications on IIS 6.0</a></li>
<li><a href="http://blog.miniasp.com/post/2008/11/Useful-tool-FastCGI-Extension-for-Internet-Information-Services-60.aspx">介紹好用工具：FastCGI Extension for IIS6.0</a></li>
<li><a href="http://blog.miniasp.com/post/2009/03/IIS-6-Identity-and-Windows-Access-Control-is-not-what-you-expected.aspx">IIS 執行的身份識別與 Windows 權限控管不是你想的那樣</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/264/feed</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>IIS6+PHP5 (ISAPI) 安裝攻略</title>
		<link>http://blog.linym.net/archives/240</link>
		<comments>http://blog.linym.net/archives/240#comments</comments>
		<pubDate>Tue, 30 Sep 2008 02:17:21 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[程式筆記]]></category>
		<category><![CDATA[系統筆記]]></category>
		<category><![CDATA[FastCGI]]></category>
		<category><![CDATA[IIS]]></category>
		<category><![CDATA[ISAPI]]></category>
		<category><![CDATA[server 2003]]></category>

		<guid isPermaLink="false">http://blog.linym.net/?p=240</guid>
		<description><![CDATA[最近因為特別需求要在 IIS6 上面跑 PHP，把以前寫的筆記拿出來看，卻發現怎麼弄也跑不起來，看了很多篇文章還是不行，研究了許久終於可以跑了，經過多次測試保證 100% 可行。 ※ 此篇是以 ISAPI 模式執行 PHP，建議使用另一篇的 FastCGI 會有較好的效能。 安裝步驟： 1. 確認 IIS 已經裝好，到 PHP 官網下載新版 PHP5 壓縮檔，並且解壓縮(假設在 C:\PHP5)。 2. 將 C:\PHP5\php.ini-dist 改名為 php.ini，然後依需求編輯設定檔內容，範例： include_path = &#34;.;C:\Inetpub\wwwroot&#34; extension_dir = &#34;C:\PHP5\ext&#34; extension=php_curl.dll extension=php_gd2.dll extension=php_mbstring.dll extension=php_mcrypt.dll extension=php_mysql.dll extension=php_mysqli.dll extension=php_openssl.dll extension=php_zip.dll date.timezone = "Asia/Taipei" 3. 對 C:\PHP5 目錄增加 IIS_WPG 群組及 IUSR_XXXX 使用者的讀取及執行權限。 (關鍵步驟，一定要兩個都增加，否則執行 PHP [...]]]></description>
			<content:encoded><![CDATA[<p>最近因為特別需求要在 IIS6 上面跑 PHP，把以前寫的筆記拿出來看，卻發現怎麼弄也跑不起來，看了很多篇文章還是不行，研究了許久終於可以跑了，經過多次測試保證 100% 可行。<br />
<em>※ 此篇是以 ISAPI 模式執行 PHP，建議使用另一篇的 <a href="http://blog.linym.net/archives/264">FastCGI</a> 會有較好的效能。</em></p>
<p><strong>安裝步驟：</strong><br />
1. 確認 IIS 已經裝好，到 <a href="http://www.php.net/downloads.php" target="_blank">PHP 官網</a>下載新版 PHP5 壓縮檔，並且解壓縮(假設在 C:\PHP5)。</p>
<p>2. 將 C:\PHP5\php.ini-dist 改名為 php.ini，然後依需求編輯設定檔內容，範例：</p>
<pre>
include_path = &quot;.;C:\Inetpub\wwwroot&quot;
extension_dir = &quot;C:\PHP5\ext&quot;

extension=php_curl.dll
extension=php_gd2.dll
extension=php_mbstring.dll
extension=php_mcrypt.dll
extension=php_mysql.dll
extension=php_mysqli.dll
extension=php_openssl.dll
extension=php_zip.dll

date.timezone = "Asia/Taipei"
</pre>
<p>3. 對 C:\PHP5 目錄增加 IIS_WPG 群組及 IUSR_XXXX 使用者的讀取及執行權限。<br />
<strong>(關鍵步驟，一定要兩個都增加，否則執行 PHP 會跳出驗證框)</strong><br />
<a href="http://blog.linym.net/wp-content/uploads/2008/09/03.jpg" target="_blank"><img src="http://blog.linym.net/wp-content/uploads/2008/09/03.jpg" alt="" title="增加權限" width="368" height="445" class="alignnone size-full wp-image-249" /></a></p>
<p>4. 加入系統環境變數 (讓 extension 及 php.ini 能順利被找到)。<br />
Path=C:\PHP5;<br />
PHPRC=C:\PHP5<br />
<a href="http://blog.linym.net/wp-content/uploads/2008/09/05.jpg" target="_blank"><img src="http://blog.linym.net/wp-content/uploads/2008/09/05.jpg" alt="" title="環境變數" width="384" height="393" class="alignnone size-full wp-image-253" /></a></p>
<p>5. 開啟 IIS 管理員，如下圖設定。<br />
<a href="http://blog.linym.net/wp-content/uploads/2008/09/06.jpg" target="_blank"><img src="http://blog.linym.net/wp-content/uploads/2008/09/06.jpg" alt="" title="IIS 管理員" width="472" height="532" class="alignnone size-full wp-image-255" /></a></p>
<p>6. 增加預設首頁 index.php<br />
<a href="http://blog.linym.net/wp-content/uploads/2008/09/08.jpg" target="_blank"><img src="http://blog.linym.net/wp-content/uploads/2008/09/08.jpg" alt="" title="預設首頁" width="471" height="430" class="alignnone size-full wp-image-259" /></a></p>
<p>7. 增加網頁服務延伸。<br />
<a href="http://blog.linym.net/wp-content/uploads/2008/09/07.jpg" target="_blank"><img src="http://blog.linym.net/wp-content/uploads/2008/09/07.jpg" alt="" title="網頁服務延伸" width="500" height="538" class="alignnone size-full wp-image-257" /></a></p>
<p>8. 重新啟動 IIS 就 OK 囉，丟一個測試檔案到網站目錄看看吧！<br />
<a href="http://blog.linym.net/wp-content/uploads/2008/09/09.jpg" target="_blank"><img src="http://blog.linym.net/wp-content/uploads/2008/09/09.jpg" alt="" title="phpinfo" width="500" height="339" class="alignnone size-full wp-image-260" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/240/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>用 PHP 讀寫 Excel 檔案</title>
		<link>http://blog.linym.net/archives/229</link>
		<comments>http://blog.linym.net/archives/229#comments</comments>
		<pubDate>Thu, 18 Sep 2008 13:47:07 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[程式筆記]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[讀取excel]]></category>

		<guid isPermaLink="false">http://blog.linym.net/?p=229</guid>
		<description><![CDATA[PHP 讀寫 Excel 的方法有很多種，例如先轉成 CSV 格式來讀，然後用特定符號去分隔欄位。但是如果遇到欄位格式不固定的 Excel 就很麻煩了，所以需要可以直接操作 excel 的方法，方便直接指定要取某欄某列的值。 如果是 Windows 系統的話可以使用 COM 元件去讀取，但缺點就是只能在 Windows 上跑，失去了跨平台性，所以也有人另外寫出可以讀寫 Excel 的類別，這次要推薦的是 PHPExcel，PHPExcel 的功能非常強大，原本就支援 Excel 2007，新版中也能讀取 Excel 2003 舊版的 Excel 囉！ 從 PHPExcel 下載回來的檔案中就包含不少範例，但是讀取的部份很簡略，所以底下貼個讀取 Excel 內容的範例： &#60;?php set_include_path(get_include_path() . PATH_SEPARATOR . &#039;./Classes/&#039;); include &#039;PHPExcel/IOFactory.php&#039;; $reader = PHPExcel_IOFactory::createReader(&#039;Excel5&#039;); // 讀取舊版 excel 檔案 $PHPExcel = $reader-&#62;load(&#34;course_table.xls&#34;); // 檔案名稱 $sheet = [...]]]></description>
			<content:encoded><![CDATA[<p>PHP 讀寫 Excel 的方法有很多種，例如先轉成 CSV 格式來讀，然後用特定符號去分隔欄位。但是如果遇到欄位格式不固定的 Excel 就很麻煩了，所以需要可以直接操作 excel 的方法，方便直接指定要取某欄某列的值。</p>
<p>如果是 Windows 系統的話可以使用 <a href="http://tw2.php.net/manual/en/class.com.php">COM</a> 元件去讀取，但缺點就是只能在 Windows 上跑，失去了跨平台性，所以也有人另外寫出可以讀寫 Excel 的類別，這次要推薦的是 <a href="http://www.codeplex.com/PHPExcel">PHPExcel</a>，<a href="http://www.codeplex.com/PHPExcel">PHPExcel</a> 的功能非常強大，原本就支援 Excel 2007，新版中也能讀取 Excel 2003 舊版的 Excel 囉！</p>
<p>從 <a href="http://www.codeplex.com/PHPExcel">PHPExcel</a> 下載回來的檔案中就包含不少範例，但是讀取的部份很簡略，所以底下貼個讀取 Excel 內容的範例：</p>
<pre title="code" class="php">

&lt;?php
set_include_path(get_include_path() . PATH_SEPARATOR . &#039;./Classes/&#039;);
include &#039;PHPExcel/IOFactory.php&#039;;

$reader = PHPExcel_IOFactory::createReader(&#039;Excel5&#039;); // 讀取舊版 excel 檔案
$PHPExcel = $reader-&gt;load(&quot;course_table.xls&quot;); // 檔案名稱
$sheet = $PHPExcel-&gt;getSheet(0); // 讀取第一個工作表(編號從 0 開始)
$highestRow = $sheet-&gt;getHighestRow(); // 取得總列數

// 一次讀取一列
for ($row = 2; $row &lt;= $highestRow; $row++) {

    for ($column = 1; $column &lt;= 9; $column++) {
		$val = $sheet-&gt;getCellByColumnAndRow($column, $row)-&gt;getValue();
        echo $val . &#039; &#039;;
	}
	echo &quot;&lt;br /&gt;&quot;;

}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/229/feed</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>撰寫 PHP 程式的一些優化建議</title>
		<link>http://blog.linym.net/archives/218</link>
		<comments>http://blog.linym.net/archives/218#comments</comments>
		<pubDate>Mon, 11 Feb 2008 15:56:50 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[程式筆記]]></category>
		<category><![CDATA[optimize]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.linym.net/archives/218</guid>
		<description><![CDATA[這裡有一篇 Tsung 翻譯的「PHP 程式效能優化的 40 條建議」，覺得很不錯。個人接觸 PHP 這個語言約有四個年頭了，再撰寫時多少會注意一些效能細節，不過有時為了讓程式碼更好看、簡短，往往就忽略掉這些細節，這篇的建議正好可以讓新手學習、老手複習一些 PHP 的最佳化技巧。 引用內容： 如果一個方法可靜態化，就對它做靜態聲明。速率可提升至4倍 echo 比 print 快 使用echo的多重參數（譯註：指用逗號而不是句點）代替字元串連接 在執行for循環之前確定最大循環數，不要每循環一次都計算最大值 註銷那些不用的變量尤其是大數組，以便釋放內存 盡量避免使用__get，__set，__autoload require_once()代價昂貴 在包含文件時使用完整路徑，解析操作系統路徑所需的時間會更少 如果你想知道腳本開始執行（譯註：即服務器端收到客戶端請求）的時刻，使用$_SERVER['REQUEST_TIME']要好於time() 函數代替正則表達式完成相同功能 str_replace函數比preg_replace函數快，但strtr函數的效率是str_replace函數的四倍 如果一個字元串替換函數，可接受數組或字元作為參數，並且參數長度不太長，那麼可以考慮額外寫一段替換程式，使得每次傳遞參數是一個字元，而不是只寫一行程式接受數組作為查詢和替換的參數 使用選擇分支語句（譯註：即switch case）好於使用多個if，else if語句 用@屏蔽錯誤消息的做法非常慢 打開apache的mod_deflate模塊 資料庫連接當使用完畢時應關掉 $row['id']的效率是$row[id]的7倍 錯誤訊息代價昂貴 盡量不要在for循環中使用函數，比如for ($x=0; $x &#60; count($array); $x)每循環一次都會調用count()函數 在function中遞增局部變量，速度是最快的。幾乎與在函數中調用局部變量的速度相當 遞增一個全局變量要比遞增一個局部變量慢2倍 遞增一個物件屬性（如：$this-&#62;prop++）要比遞增一個局部變量慢3倍 遞增一個未預定義的局部變量要比遞增一個預定義的局部變量慢9至10倍 僅定義一個局部變量而沒在函數中調用它，同樣會減慢速度（其程度相當於遞增一個局部變量）。PHP大概會檢查看是否存在全局變量 方法調用看來與類中定義的方法的數量無關，因為我（在測試方法之前和之後都）添加了10個方法，但性能上沒有變化 派生類中的方法運行起來要快於在基類中定義的同樣的方法 調用帶有一個參數的空函數，其花費的時間相當於執行7至8次的局部變量遞增操作。類似的方法調用所花費的時間接近於15次的局部變量遞增操作 用單引號代替雙引號來包含字元串，這樣做會更快一些。因為PHP會在雙引號包圍的字元串中搜尋變量，單引號則不會。當然，只有當你不需要在字元串中包含變量時才可以這麼做 輸出多個字元串時，用逗號代替句點來分隔字元串，速度更快。註意：只有echo能這麼做，它是一種可以把多個字元串當作參數的“函數”（譯註：PHP手冊中說echo是語言結構，不是真正的函數，故把函數加上了雙引號） Apache解析一個PHP腳本的時間要比解析一個靜態HTML頁面慢2至10倍。盡量多用靜態HTML頁面，少用腳本 除非腳本可以緩存，否則每次調用時都會重新編譯一次。引入一套PHP緩存機制通常可以提升25%至100%的性能，以免除編譯開銷 盡量做緩存，可使用memcached。memcached是一款高性能的內存物件緩存系統，可用來加速動態Web應用程式，減輕數據庫負載。對運算碼 (OP code)的緩存很有用，使得腳本不必為每個請求做重新編譯 [...]]]></description>
			<content:encoded><![CDATA[<p>這裡有一篇 Tsung 翻譯的「<a href="http://plog.longwin.com.tw/programming/2008/02/05/php_optimizing_40_comment_2008" target="_blank">PHP 程式效能優化的 40 條建議</a>」，覺得很不錯。個人接觸 PHP 這個語言約有四個年頭了，再撰寫時多少會注意一些效能細節，不過有時為了讓程式碼更好看、簡短，往往就忽略掉這些細節，這篇的建議正好可以讓新手學習、老手複習一些 PHP 的最佳化技巧。</p>
<p><strong>引用內容：</strong></p>
<ol>
<li>如果一個方法可靜態化，就對它做靜態聲明。速率可提升至4倍</li>
<li>echo 比 print 快</li>
<li>使用echo的多重參數（譯註：指用逗號而不是句點）代替字元串連接</li>
<li>在執行for循環之前確定最大循環數，不要每循環一次都計算最大值</li>
<li>註銷那些不用的變量尤其是大數組，以便釋放內存</li>
<li>盡量避免使用__get，__set，__autoload</li>
<li>require_once()代價昂貴</li>
<li>在包含文件時使用完整路徑，解析操作系統路徑所需的時間會更少</li>
<li>如果你想知道腳本開始執行（譯註：即服務器端收到客戶端請求）的時刻，使用$_SERVER['REQUEST_TIME']要好於time()</li>
<li>函數代替正則表達式完成相同功能</li>
<li>str_replace函數比preg_replace函數快，但strtr函數的效率是str_replace函數的四倍</li>
<li>如果一個字元串替換函數，可接受數組或字元作為參數，並且參數長度不太長，那麼可以考慮額外寫一段替換程式，使得每次傳遞參數是一個字元，而不是只寫一行程式接受數組作為查詢和替換的參數</li>
<li>使用選擇分支語句（譯註：即switch case）好於使用多個if，else if語句</li>
<li>用@屏蔽錯誤消息的做法非常慢</li>
<li>打開apache的mod_deflate模塊</li>
<li>資料庫連接當使用完畢時應關掉</li>
<li>$row['id']的效率是$row[id]的7倍</li>
<li>錯誤訊息代價昂貴</li>
<li>盡量不要在for循環中使用函數，比如for ($x=0; $x &lt; count($array); $x)每循環一次都會調用count()函數</li>
<li>在function中遞增局部變量，速度是最快的。幾乎與在函數中調用局部變量的速度相當</li>
<li>遞增一個全局變量要比遞增一個局部變量慢2倍</li>
<li>遞增一個物件屬性（如：$this-&gt;prop++）要比遞增一個局部變量慢3倍</li>
<li>遞增一個未預定義的局部變量要比遞增一個預定義的局部變量慢9至10倍</li>
<li>僅定義一個局部變量而沒在函數中調用它，同樣會減慢速度（其程度相當於遞增一個局部變量）。PHP大概會檢查看是否存在全局變量</li>
<li>方法調用看來與類中定義的方法的數量無關，因為我（在測試方法之前和之後都）添加了10個方法，但性能上沒有變化</li>
<li>派生類中的方法運行起來要快於在基類中定義的同樣的方法</li>
<li>調用帶有一個參數的空函數，其花費的時間相當於執行7至8次的局部變量遞增操作。類似的方法調用所花費的時間接近於15次的局部變量遞增操作</li>
<li>用單引號代替雙引號來包含字元串，這樣做會更快一些。因為PHP會在雙引號包圍的字元串中搜尋變量，單引號則不會。當然，只有當你不需要在字元串中包含變量時才可以這麼做</li>
<li>輸出多個字元串時，用逗號代替句點來分隔字元串，速度更快。註意：只有echo能這麼做，它是一種可以把多個字元串當作參數的“函數”（譯註：PHP手冊中說echo是語言結構，不是真正的函數，故把函數加上了雙引號）</li>
<li>Apache解析一個PHP腳本的時間要比解析一個靜態HTML頁面慢2至10倍。盡量多用靜態HTML頁面，少用腳本</li>
<li>除非腳本可以緩存，否則每次調用時都會重新編譯一次。引入一套PHP緩存機制通常可以提升25%至100%的性能，以免除編譯開銷</li>
<li>盡量做緩存，可使用memcached。memcached是一款高性能的內存物件緩存系統，可用來加速動態Web應用程式，減輕數據庫負載。對運算碼 (OP code)的緩存很有用，使得腳本不必為每個請求做重新編譯</li>
<li>當操作字元串並需要檢驗其長度是否滿足某種要求時，你想當然地會使用strlen()函數。此函數執行起來相當快，因為它不做任何計算，只返回在zval 結構（C的內置數據結構，用於存儲PHP變量）中存儲的已知字元串長度。但是，由於strlen()是函數，多多少少會有些慢，因為函數調用會經過諸多步驟，如字母小寫化（譯註：指函數名小寫化，PHP不區分函數名大小寫），會跟隨被調用的函數一起執行。在某些情況下，你可以使用isset() 技巧加速執行你的程式<br />舉例如下:<br />if (strlen($foo) &lt; 5) { echo "Foo is too short"; }<br />與下面的技巧做比較:<br />if (!isset($foo{5})) { echo "Foo is too short"; }<br />調用isset()恰巧比strlen()快，因為與後者不同的是，isset()作為一種語言結構，意味著它的執行不需要函數查找和字母小寫化。也就是說，實際上在檢驗字元串長度的頂層程式中你沒有花太多開銷</li>
<li>當執行變數$i的遞增或遞減時，$i++會比++$i慢一些。這種差異是PHP特有的，並不適用於其他語言，所以請不要修改你的C或Java程式並指望它們能立即變快，沒用的。++$i更快是因為它只需要3條指令(opcodes)，$i++則需要4條指令。後置遞增實際上會產生一個臨時變量，這個臨時變量隨後被遞增。而前置遞增直接在原值上遞增。這是最優化處理的一種，正如Zend的PHP優化器所作的那樣。牢記這個優化處理不失為一個好主意，因為並不是所有的指令優化器都會做同樣的優化處理，並且存在大量沒有裝配指令優化器的網際網路服務提供商（ISPs）和服務器</li>
<li>並不是所有都要使用OOP，面向物件往往開銷很大，每個方法和物件調用都會消耗很多Memory</li>
<li>並非要用 class 實現所有的數據結構，數組也很有用</li>
<li>不要把方法細分得過多，仔細想想你真正打算重用的是哪些程式?</li>
<li>當你需要時，你總能把程式分解成方法</li>
<li>盡量採用大量的PHP內置函數</li>
<li>如果在程式中存在大量耗時的函數，你可以考慮用C擴展的方式實現它們</li>
<li>評估檢驗(profile)你的程式。檢驗器會告訴你，程式的哪些部分消耗了多少時間。Xdebug調試器包含了檢驗程式，評估檢驗總體上可以顯示出程式的瓶頸</li>
<li>mod_zip可作為Apache模塊，用來即時壓縮你的數據，並可讓數據傳輸量降低80%</li>
<li>另一篇<a href="http://phplens.com/lens/php-book/optimizing-debugging-php.php" target="_blank" title="A HOWTO on Optimizing PHP with tips and methodologies">優化PHP</a>的精彩文章，由John Lim撰寫 </li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/218/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>TwSMS 發簡訊 (Linux C 版)</title>
		<link>http://blog.linym.net/archives/216</link>
		<comments>http://blog.linym.net/archives/216#comments</comments>
		<pubDate>Sun, 20 Jan 2008 17:39:20 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[程式筆記]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[TwSMS]]></category>
		<category><![CDATA[傳簡訊]]></category>

		<guid isPermaLink="false">http://blog.linym.net/archives/216</guid>
		<description><![CDATA[台灣簡訊(TwSMS)是國內一家線上傳簡訊的服務商，提供文字簡訊、語音簡訊等服務，價格也很合理，最重要的是有提供 API 介面，方便用戶在自己的程式中加入發送簡訊功能，官網已經有提供不少範例(PHP/ASP/JSP/Java/Perl/VB/BCB/Delphi)，這邊也有 Ruby 的版本，不過就是沒看到 C 的，所以大略寫了一個 Linux C 版本，打算加入自己的嵌入式專題使用。 TwSMS 提供的 API 很簡單，只要由 HTTP 對 API server 發送 Request 即可，接著 server 就會回傳結果。程式先建立一個 socket 連線，然後發送簡訊，最後再擷取回傳碼檢查是否成功。 #include &#60;stdio.h&#62; #include &#60;stdlib.h&#62; #include &#60;string.h&#62; #include &#60;sys/socket.h&#62; #include &#60;netinet/in.h&#62; #include &#60;arpa/inet.h&#62; #include &#60;netdb.h&#62; int main() { /* TWSMS 相關設定 */ char *username = &#34;username&#34;; // 帳號 char *password = [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.twsms.com/" target="_blank">台灣簡訊</a>(TwSMS)是國內一家線上傳簡訊的服務商，提供文字簡訊、語音簡訊等服務，價格也很合理，最重要的是有提供 API 介面，方便用戶在自己的程式中加入發送簡訊功能，官網已經有提供不少範例(PHP/ASP/JSP/Java/Perl/VB/BCB/Delphi)，<a href="http://github.com/cfc/twsmsr/tree/master" target="_blank">這邊</a>也有 Ruby 的版本，不過就是沒看到 C 的，所以大略寫了一個 Linux C 版本，打算加入自己的嵌入式專題使用。</p>
<p>TwSMS 提供的 API 很簡單，只要由 HTTP 對 API server 發送 Request 即可，接著 server 就會回傳結果。程式先建立一個 socket 連線，然後發送簡訊，最後再擷取回傳碼檢查是否成功。</p>
<pre title="code" class="cpp">

#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;
#include &lt;sys/socket.h&gt;
#include &lt;netinet/in.h&gt;
#include &lt;arpa/inet.h&gt;
#include &lt;netdb.h&gt;

int main()
{
	/* TWSMS 相關設定 */
	char *username = &quot;username&quot;;   // 帳號
	char *password = &quot;password&quot;; // 密碼
	char *type = &quot;now&quot;;         // 發送型態
	char *mobile = &quot;0912xxxxxx&quot;; // 電話
	char *message = &quot;簡訊測試&quot;; // 簡訊內容
	char *encoding = &quot;big5&quot;;    // 簡訊內容編碼
	char *popup = &quot;&quot;;          // 使用 POPUP 顯示
	char *mo = &quot;&quot;;             // 使用雙向簡訊
	char *vldtime = &quot;86400&quot;;    // 簡訊有效期限(秒)
	char *dlvtime = &quot;&quot;;         // 預約時間

	int sockfd;
	int len = 0;
	char *host = &quot;api.twsms.com&quot;;
	char msg[512], MSGData[512], buf[512];
	char *res, *checkRes;
	struct sockaddr_in address;
	struct hostent *hostinfo;

	bzero(&amp;address, sizeof(address));
	hostinfo = gethostbyname(host);
	if (!hostinfo) {
		fprintf(stderr, &quot;no host: %s\n&quot;, host);
		exit(1);
	}
	address.sin_family = AF_INET;
	address.sin_port = htons(80);
	address.sin_addr = *(struct in_addr *)*hostinfo-&gt;h_addr_list;

	/* Create socket */
	sockfd = socket(AF_INET, SOCK_STREAM, 0);

	/* Connect to server */
	if (connect(sockfd, (struct sockaddr *)&amp;address, sizeof(address)) == -1) {
		perror(&quot;connect faild!\n&quot;);
		exit(1);
	}

	/* Request string */
	len = snprintf(msg, 512,
				  &quot;username=%s&amp;password=%s&amp;type=%s&amp;encoding=%s&amp;popup=%s&amp;mo=%s&amp;mobile=%s&quot;
				  &quot;&amp;message=%s&amp;vldtime=%s&amp;dlvtime=%s&quot;, username, password, type, encoding,
				  popup, mo, mobile, message, vldtime, dlvtime);

	/* HTTP request content */
	snprintf(MSGData, 512,
			&quot;POST /send_sms.php HTTP/1.1\r\n&quot;
			&quot;Host: %s\r\n&quot;
			&quot;Content-Length: %d\r\n&quot;
			&quot;Content-Type: application/x-www-form-urlencoded\r\n&quot;
			&quot;Connection: Close\r\n\r\n&quot;
			&quot;%s\r\n&quot;, host, len, msg);

	/* Send message */
	send(sockfd, MSGData, strlen(MSGData), 0);

	/* Response message */
	recv(sockfd, buf, 512, 0);

	for (res = strtok(buf, &quot;\n&quot;); strncmp(res, &quot;resp&quot;, 4) != 0; res = strtok(NULL, &quot;\n&quot;));
	checkRes = strtok(res, &quot;=&quot;);
	checkRes = strtok(NULL, &quot;=&quot;);

	if (atoi(checkRes) &lt;= 0) {
		printf(&quot;傳送失敗\n&quot;);
	} else {
		printf(&quot;傳送完成\n&quot;);
	}

	close(sockfd);
	return 0;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/216/feed</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>WordPress 2.3.2 無法中文化問題</title>
		<link>http://blog.linym.net/archives/214</link>
		<comments>http://blog.linym.net/archives/214#comments</comments>
		<pubDate>Thu, 10 Jan 2008 13:38:05 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[程式筆記]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[中文化]]></category>

		<guid isPermaLink="false">http://blog.linym.net/archives/214</guid>
		<description><![CDATA[WordPress 最近已經更新到 2.3.2 版了，趁著最近專題發表結束的空閒來更新一下，到官方抓了新版以及 Kirin Lin 的中文語系，由於 2.3.2 只是些 bug 及安全性修正，所以就直接採用覆蓋大法更新了。完工之後，咦？怎麼變英文介面了，wp-config.php 設定沒錯阿，於是求助 google 大神，馬上就找到了這篇，原來在 PHP 5.2.x 以及 64bit 系統下會有這個問題，登入 BlueHost 主機的後台看一下，果然沒錯，開始修正囉！ 其實只要修正一行即可： wp-includes/gettext.php LINE:117 if ($magic == ($MAGIC1 &#38; 0xFFFFFFFF) &#124;&#124; $magic == ($MAGIC3 &#38; 0xFFFFFFFF)) { // to make sure it works for 64-bit platforms 更改成： if ($magic == $MAGIC1 &#124;&#124; $magic == $MAGIC3) [...]]]></description>
			<content:encoded><![CDATA[<p>WordPress 最近已經更新到 2.3.2 版了，趁著最近專題發表結束的空閒來更新一下，到官方抓了新版以及 <a href="http://kirin.lin.googlepages.com/">Kirin Lin</a> 的中文語系，由於 2.3.2 只是些 bug 及安全性修正，所以就直接採用覆蓋大法更新了。完工之後，咦？怎麼變英文介面了，wp-config.php 設定沒錯阿，於是求助 google 大神，馬上就找到了<a href="http://www.wordpress.com.tw/wp/?p=80" target="_blank">這篇</a>，原來在 PHP 5.2.x 以及 64bit 系統下會有這個問題，登入 BlueHost 主機的後台看一下，果然沒錯，開始修正囉！</p>
<p>其實只要修正一行即可：<br />
wp-includes/gettext.php  LINE:117</p>
<pre title="code" class="php">

if ($magic == ($MAGIC1 &amp; 0xFFFFFFFF) || $magic == ($MAGIC3 &amp; 0xFFFFFFFF)) { // to make sure it works for 64-bit platforms
</pre>
<p>更改成：</p>
<pre title="code" class="php">

if ($magic == $MAGIC1 || $magic == $MAGIC3) { // &lt;- 64 BIT FIX: CHANGE THIS LINE!
</pre>
<p>ok!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/214/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Google Map 地圖定位</title>
		<link>http://blog.linym.net/archives/213</link>
		<comments>http://blog.linym.net/archives/213#comments</comments>
		<pubDate>Thu, 10 Jan 2008 12:40:38 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Other]]></category>
		<category><![CDATA[程式筆記]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://blog.linym.net/archives/213</guid>
		<description><![CDATA[Google Map 提供的 API 實在是強大又好用，結合 GPS 很快就可以做出地圖定位的網站，將之前的 Urmap 範例修改了一下，成為 Google Map 地圖定位系統，為了能夠展示所以將座標先寫好讓它自己動態更新，其中按下停止按鈕會畫出所有紀錄點的連線，可做路徑追蹤。 Google Map API 網路上的資源已經相當豐富了，在此就不多敘述，比較特別的是畫折線(polyline)的部份，如果用原始的 GPolyline 方法來畫，大概幾十個點就需要運算很久，甚至導致瀏覽器 crash，所以 API 後來又加入了編碼折線(encodedPolyline)的功能，先將所有的點用特定演算法轉換成一串文字符號，再丟給 GPolyline.fromEncoded 顯示，幾乎是馬上就顯示出來了，差很多喔，而這個編碼演算法也已經有人寫好囉！請看：Encoding polylines for Google Maps]]></description>
			<content:encoded><![CDATA[<p>Google Map 提供的 <a href="http://code.google.com/apis/maps/documentation/" target="_blank">API</a> 實在是強大又好用，結合 GPS 很快就可以做出地圖定位的網站，將之前的 Urmap 範例修改了一下，成為 <a href="http://map.linym.net/" target="_blank">Google Map 地圖定位系統</a>，為了能夠展示所以將座標先寫好讓它自己動態更新，其中按下停止按鈕會畫出所有紀錄點的連線，可做路徑追蹤。</p>
<p><a href="http://code.google.com/apis/maps/documentation/" target="_blank">Google Map API</a> 網路上的資源已經相當豐富了，在此就不多敘述，比較特別的是畫折線(polyline)的部份，如果用原始的 GPolyline 方法來畫，大概幾十個點就需要運算很久，甚至導致瀏覽器 crash，所以 API 後來又加入了編碼折線(encodedPolyline)的功能，先將所有的點用特定演算法轉換成一串文字符號，再丟給 GPolyline.fromEncoded 顯示，幾乎是馬上就顯示出來了，差很多喔，而這個編碼演算法也已經有人寫好囉！請看：<a href="http://facstaff.unca.edu/mcmcclur/GoogleMaps/EncodePolyline/" target="_blank">Encoding polylines for Google Maps</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/213/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>CodeIgniter 設定 MySQL 編碼</title>
		<link>http://blog.linym.net/archives/212</link>
		<comments>http://blog.linym.net/archives/212#comments</comments>
		<pubDate>Sat, 22 Dec 2007 15:21:51 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[程式筆記]]></category>
		<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[編碼]]></category>

		<guid isPermaLink="false">http://blog.linym.net/archives/212</guid>
		<description><![CDATA[※ CodeIgniter 1.6 已釋出，不需再做這篇的修正了哦！ 先前有提到過 CodeIgniter 這個 PHP Framework，也用它做了幾個 case，當然開發速度不能說快上多少，但確實讓程式碼變得整齊優雅許多。 使用 CI 目前遇到第一個問題是存取 MySQL 資料的問題，在 MySQL 4.1 以後採用了多層式編碼設定，簡單說就是不管是資料庫、資料表、欄位或是 Client 連線階段，都可以分別設定編碼，所以即使 server 都改成了 utf8，PHP 到 MySQL Server 的這個 connection 卻還是預設的(latin1)，許多亂碼就是這樣造成的，應該已經有不少人知道解決方法，就是先送出一個改變編碼的查詢：SET NAMES &#39;charset&#39;。 然而目前 CodeIgniter 並沒有這樣的設計，所以只好自行改 code 囉！ Step1：修改 system/application/config/database.php 增加一項：$db[&#39;default&#39;][&#39;charset&#39;] = &#34;utf8&#34;; Step2：修改 system/database/DB_driver.php 在 32 行之後的宣告增加：var $charset = &#39;&#39;; 接著 96 行的陣列增加：&#39;charset&#39; => &#39;&#39;, Step3：修改 [...]]]></description>
			<content:encoded><![CDATA[<p><strong>※ CodeIgniter 1.6 已釋出，不需再做這篇的修正了哦！</strong></p>
<p>先前有<a href="http://blog.linym.net/archives/162">提到</a>過 <a href="http://codeigniter.com/" target="_blank">CodeIgniter</a> 這個 PHP Framework，也用它做了幾個 case，當然開發速度不能說快上多少，但確實讓程式碼變得整齊優雅許多。</p>
<p>使用 CI 目前遇到第一個問題是存取 MySQL 資料的問題，在 MySQL 4.1 以後採用了多層式編碼設定，簡單說就是不管是資料庫、資料表、欄位或是 Client 連線階段，都可以分別設定編碼，所以即使 server 都改成了 utf8，PHP 到 MySQL Server 的這個 connection 卻還是預設的(latin1)，許多亂碼就是這樣造成的，應該已經有不少人知道解決方法，就是先送出一個改變編碼的查詢：SET NAMES &#39;charset&#39;。<br />
然而目前 CodeIgniter 並沒有這樣的設計，所以只好自行改 code 囉！</p>
<p><strong>Step1：修改 system/application/config/database.php</strong><br />
增加一項：$db[&#39;default&#39;][&#39;charset&#39;]  = &quot;utf8&quot;;</p>
<p><strong>Step2：修改 system/database/DB_driver.php</strong><br />
在 32 行之後的宣告增加：var $charset        = &#39;&#39;;<br />
接著 96 行的陣列增加：&#39;charset&#39;	=> &#39;&#39;,</p>
<p><strong>Step3：修改 system/database/drivers/mysql/mysql_driver.php</strong><br />
74 行 return 前加入：</p>
<pre title="code" class="php">

if (!empty($this-&gt;charset))
{
    @mysql_query(&quot;SET NAMES $this-&gt;charset&quot;);
}
</pre>
<p>這樣就 ok 了，如果使用 mysqli 請如法炮製。另外如果主機環境符合，可使用 PHP 內建函式來設定：</p>
<pre title="code" class="php">

// PHP &gt;= 5.2.3，MySQL &gt;= 5.0.7 for mysql
@mysql_set_charset($this-&gt;charset, $this-&gt;conn_id);
// PHP &gt;= 5.0.5，MySQL &gt;= 5.0.6 for mysqli
@mysqli_set_charset($this-&gt;conn_id, $this-&gt;charset);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/212/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>編譯 ZD1211 無線網卡驅動</title>
		<link>http://blog.linym.net/archives/209</link>
		<comments>http://blog.linym.net/archives/209#comments</comments>
		<pubDate>Mon, 19 Nov 2007 11:36:22 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Other]]></category>
		<category><![CDATA[硬體筆記]]></category>
		<category><![CDATA[driver]]></category>
		<category><![CDATA[wireless]]></category>
		<category><![CDATA[zd1211]]></category>

		<guid isPermaLink="false">http://blog.linym.net/archives/209</guid>
		<description><![CDATA[關於如何編譯 ZD1211/ZD1211B 晶片的 USB 無線網卡 driver，經常在各大討論區及 BBS 看到有人提出相同的問題，因此來寫個教學。 前往 ZD1211 專案網站可以知道目前有三種版本的驅動，其中建議使用 zd1211rw 這個版本，因為它持續在更新且已納入 Linux 2.6.18 以後的 kernel 裡。zd1211rw 支援這三種晶片： ZyDAS ZD1211 ZyDAS ZD1211B Atheros AR5007UG 不過既然都已經納入 kernel 了為什麼還要編譯驅動？因為還是有很多產品的 USB ID 不能被 zd1211rw 所辨識(我的 PCI GW-US54GXS 就是)，當然就沒辦法驅動囉！這篇要做的就是從 kernel 裡的 zd1211rw source code 加入對應的 USB ID，主機環境是 ubuntu 7.10，其他版本應該也差不多。 首先要安裝編譯相關套件 &#038; 下載 linux source $ sudo apt-get install [...]]]></description>
			<content:encoded><![CDATA[<p>關於如何編譯 ZD1211/ZD1211B 晶片的 USB 無線網卡 driver，經常在各大討論區及 BBS 看到有人提出相同的問題，因此來寫個教學。</p>
<p>前往 <a href="http://zd1211.wiki.sourceforge.net/" target="_blank">ZD1211</a> 專案網站可以知道目前有三種版本的驅動，其中建議使用 <a href="http://www.linuxwireless.org/en/users/Drivers/zd1211rw" target="_blank">zd1211rw</a> 這個版本，因為它持續在更新且已納入 Linux 2.6.18 以後的 kernel 裡。zd1211rw 支援這三種晶片：</p>
<ul>
<li>ZyDAS ZD1211</li>
<li>ZyDAS ZD1211B</li>
<li>Atheros AR5007UG</li>
</ul>
<p>不過既然都已經納入 kernel 了為什麼還要編譯驅動？因為還是有很多產品的 USB ID 不能被 zd1211rw 所辨識(我的 PCI GW-US54GXS 就是)，當然就沒辦法驅動囉！這篇要做的就是從 kernel 裡的 zd1211rw source code 加入對應的 USB ID，主機環境是 ubuntu 7.10，其他版本應該也差不多。</p>
<p><strong>首先要安裝編譯相關套件 &#038; 下載 linux source</strong><br />
$ sudo apt-get install build-essential kernel-package linux-source</p>
<p><strong>切換至 src 目錄並解開 linux source</strong><br />
$ cd /usr/src<br />
$ sudo tar -xjvf linux-source-2.6.22.tar.bz2</p>
<p><strong>拷貝 kernel 設定檔(.config) 至 linux source</strong><br />
$ sudo cp linux-headers-2.6.22-14-generic/.config linux-source-2.6.22</p>
<p><strong>編輯 zd_usb.c 加入新 USB ID，可利用 lsusb 指令可以找出網卡的 ID，如：2019:5303</strong><br />
$ cd linux-source-2.6.22<br />
$ sudo vim drivers/net/wireless/zd1211rw/zd_usb.c<br />
在檔案開頭不遠處可以看到一堆 USB ID 號碼，就是要加進這裡面，GW-US54GXS 是 ZD1211B 晶片，所以在 ZD1211B 下方增加一行：<br />
/* ZD1211B */<br />
{ USB_DEVICE(0x2019, 0x5303), .driver_info = DEVICE_ZD1211B },<br />
確認後就存檔離開</p>
<p><strong>開始編譯驅動</strong><br />
$ sudo mkdir .tmp_versions<br />
$ sudo make drivers/net/wireless/zd1211rw/zd1211rw.ko</p>
<p><strong>沒錯誤就會產生 zd1211rw.ko，將它覆蓋原本系統中的</strong><br />
$ sudo cp drivers/net/wireless/zd1211rw/zd1211rw.ko /lib/modules/`uname -r`/kernel/drivers/net/wireless/zd1211rw<br />
$ sudo depmod -a</p>
<p>重開機應該就可以正確驅動了:D</p>
<p>參考資料：<br />
<a href="http://www.linuxwireless.org/en/users/Drivers/zd1211rw/AddID" target="_blank">Adding new device IDs to zd1211rw</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/209/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>建立網頁縮圖(Webthumb)</title>
		<link>http://blog.linym.net/archives/196</link>
		<comments>http://blog.linym.net/archives/196#comments</comments>
		<pubDate>Fri, 05 Oct 2007 15:45:22 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[程式筆記]]></category>
		<category><![CDATA[Webthumb]]></category>
		<category><![CDATA[網頁]]></category>
		<category><![CDATA[縮圖]]></category>

		<guid isPermaLink="false">http://blog.linym.net/archives/196</guid>
		<description><![CDATA[目前不少網站都有自動產生網頁縮圖的功能，像是 HEMiDEMi、funP 推推王、Alexa 等等，雖然很想知道其中所使用的技術，不過似乎很難找到相關文章，大多是倚賴提供縮圖服務的網站居多。 Bluga.net WebThumb 我覺得很不錯的縮圖服務網站，每個月可免費建立 250 組縮圖，且提供 API 可以應用在程式上，產生縮圖速度算滿快的，大約 2~5 分鐘即可顯示。 artViper Website Tools 這網站有提供一些 Website Tools，其中就有網頁縮圖的功能。 Website Thumbnail Generator 這個是不需要依賴其他網站的，使用了 IECapt 這個小工具，所以主機只能是 Windows，配合 PHP 來自動產生縮圖。 延伸閱讀： Website Thumbnail Creators (Website Snapshot Generators)]]></description>
			<content:encoded><![CDATA[<p>目前不少網站都有自動產生網頁縮圖的功能，像是 <a href="http://www.hemidemi.com/" target="_blank">HEMiDEMi</a>、<a href="http://funp.com/" target="_blank">funP 推推王</a>、<a href="http://www.alexa.com/" target="_blank">Alexa</a> 等等，雖然很想知道其中所使用的技術，不過似乎很難找到相關文章，大多是倚賴提供縮圖服務的網站居多。</p>
<p><a href="http://webthumb.bluga.net/" target="_blank">Bluga.net WebThumb</a><br />
我覺得很不錯的縮圖服務網站，每個月可免費建立 250 組縮圖，且提供 API 可以應用在程式上，產生縮圖速度算滿快的，大約 2~5 分鐘即可顯示。</p>
<p><a href="http://www.artviper.com/tools.php" target="_blank">artViper Website Tools</a><br />
這網站有提供一些 Website Tools，其中就有網頁縮圖的功能。</p>
<p><a href="http://www.zubrag.com/scripts/website-thumbnail-generator.php" target="_blank">Website Thumbnail Generator</a><br />
這個是不需要依賴其他網站的，使用了 IECapt 這個小工具，所以主機只能是 Windows，配合 PHP 來自動產生縮圖。</p>
<p>延伸閱讀：<br />
<a href="http://www.zubrag.com/articles/create-website-snapshot-thumbnail.php" target="_blank">Website Thumbnail Creators (Website Snapshot Generators)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/196/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>用 PHP 寫 RS232 串列通訊程式</title>
		<link>http://blog.linym.net/archives/187</link>
		<comments>http://blog.linym.net/archives/187#comments</comments>
		<pubDate>Tue, 02 Oct 2007 11:25:06 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[程式筆記]]></category>
		<category><![CDATA[serial]]></category>

		<guid isPermaLink="false">http://blog.linym.net/archives/187</guid>
		<description><![CDATA[相信經常在翻 PHP 手冊的人應該都有察覺，PHP 不只是可以用來開發網頁程式而已，很多其他語言能完成的工作 PHP 也都做的到，例如透過 PHP 的 Direct IO Functions 就可以對 Serial port 溝通，而且可以在 Windows 下執行，一般在 Windows 要實做 com port 通訊程式，大多是透過像 VB/VC++/C++ Builder 這類程式所提供的元件來撰寫，不過用 PHP 就可以很快實做出一般的功能囉！ 在開始之前要先讓 PHP 支援 dio 才行，5.1.0 版之後已經將 dio 移至 PECL 了，可以到 PHP 官網下載編譯好的 PECL，解壓縮後將裡面的 php_dio.dll 放到 PHP 目錄的 ext 底下，接著修改 php.ini 加入 extension=php_dio.dll 即可。 在 Windows 底下讀取 COM1 的例子： [...]]]></description>
			<content:encoded><![CDATA[<p>相信經常在翻 PHP 手冊的人應該都有察覺，PHP 不只是可以用來開發網頁程式而已，很多其他語言能完成的工作 PHP 也都做的到，例如透過 PHP 的 <a href="http://tw2.php.net/manual/en/ref.dio.php" target="_blank">Direct IO Functions</a> 就可以對 Serial port 溝通，而且可以在 Windows 下執行，一般在 Windows 要實做 com port 通訊程式，大多是透過像 VB/VC++/C++ Builder 這類程式所提供的元件來撰寫，不過用 PHP 就可以很快實做出一般的功能囉！</p>
<p>在開始之前要先讓 PHP 支援 dio 才行，5.1.0 版之後已經將 dio 移至 PECL 了，可以到 PHP 官網下載編譯好的 <a href="http://tw2.php.net/downloads.php" target="_blank">PECL</a>，解壓縮後將裡面的 <strong>php_dio.dll</strong> 放到 PHP 目錄的 ext 底下，接著修改 php.ini 加入 <strong>extension=php_dio.dll</strong> 即可。</p>
<p>在 Windows 底下讀取 COM1 的例子：</p>
<pre title="code" class="php">

&lt;?php
exec(&#039;mode COM1: baud=19200 data=8 stop=1 parity=n&#039;);
$fd = dio_open(&#039;COM1:&#039;, O_RDWR);
while (1) {
    $data = dio_read($fd, 1);
    if ($data) {
        echo $data;
    }
}
dio_close($fd);
?&gt;
</pre>
<p>寫法跟在 Linux 用 C 寫 serial 通訊程式差不多，其中 mode 是 Windows 命令列一個設定 serial port 組態的工具(類似 Linux 的 stty)，可以打 mode /? 看詳細說明，設定好傳輸率等，接著用 dio_open 開啟裝置，然後就可以做存取的動作囉！</p>
<p><strong>※ 2009/04/10 補充：</strong><br />
有不少人看了這篇之後，問我要怎麼用 PHP 讀取 GPS 資料。<br />
在這邊要跟各位補充的是，如果您想要用瀏覽器在網頁執行 PHP，然後去讀取 GPS，這的確可以抓到資料，但其實是存在很多問題的，因為 Web 架構並不適合應用在這類有「持續連接」行為的地方，所以有可能發生 timeout、資源佔用、搶奪，嚴重的話會導致伺服器 crash。</p>
<p>但是如果一定要用 PHP 實作，建議應該是利用 command line 的方式執行，在背景專門負責抓 GPS 資料 ，並且將座標資料存入檔案或資料庫，然後網頁再去存取座標資料，如此一來便不會影響到 Web 運作。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/187/feed</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>C 語言中 printf 的問題(續)</title>
		<link>http://blog.linym.net/archives/186</link>
		<comments>http://blog.linym.net/archives/186#comments</comments>
		<pubDate>Sun, 30 Sep 2007 03:03:53 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[程式筆記]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.linym.net/archives/186</guid>
		<description><![CDATA[在前一篇當中提到了 printf 結果異常的問題，在睡前翻了一下手邊借來的「C Primer Plus」，沒想到就有提到這個問題，印象中其他書籍似乎都沒有講到，C Primer 系列果然是好書！ 簡單來說就是 C 語言中，compiler 可以選擇先計算函數中的哪個參數，以增加編譯程式的效率，所以前一篇的例子： printf(&#34;%d, %d&#34;, age, age++); compiler 很可能會先算第二個參數，先改變了 num 數值，這樣就造成結果不如預期了。 在「C Primer Plus 5/e 中文精華版」第五章有寫道，遵循以下原則可以避免這些問題： 請勿在函數當中，對使用不止一次的參數使用遞增或遞減運算子。 請勿在運算式當中，對使用不止一次的變數使用遞增或遞減運算子。 第一點就是上面所說的例子，第二點的例子如下： n = 3; y = n++ + n++; 在 C 標準中並沒有定義這行程式會如何執行，是哪一個先加 1 再運算，還是都先不加，造成了含糊不清的結果，應當避免這種寫法。]]></description>
			<content:encoded><![CDATA[<p>在<a href="http://blog.linym.net/archives/185">前一篇</a>當中提到了 printf 結果異常的問題，在睡前翻了一下手邊借來的「C Primer Plus」，沒想到就有提到這個問題，印象中其他書籍似乎都沒有講到，C Primer 系列果然是好書！</p>
<p>簡單來說就是 C 語言中，compiler 可以選擇先計算函數中的哪個參數，以增加編譯程式的效率，所以前一篇的例子：</p>
<pre title="code" class="c">

printf(&quot;%d, %d&quot;, age, age++);
</pre>
<p>compiler 很可能會先算第二個參數，先改變了 num 數值，這樣就造成結果不如預期了。</p>
<p>在「<a href="http://www.books.com.tw/exep/prod/booksfile.php?item=0010322617" target="_blank">C Primer Plus 5/e 中文精華版</a>」第五章有寫道，遵循以下原則可以避免這些問題：</p>
<blockquote>
<ol>
<li>請勿在函數當中，對使用不止一次的參數使用遞增或遞減運算子。</li>
<li>請勿在運算式當中，對使用不止一次的變數使用遞增或遞減運算子。</li>
</ol>
</blockquote>
<p>第一點就是上面所說的例子，第二點的例子如下：</p>
<pre title="code" class="c">

n = 3;
y = n++ + n++;
</pre>
<p>在 C 標準中並沒有定義這行程式會如何執行，是哪一個先加 1 再運算，還是都先不加，造成了含糊不清的結果，應當避免這種寫法。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/186/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>C 語言中 printf 的問題</title>
		<link>http://blog.linym.net/archives/185</link>
		<comments>http://blog.linym.net/archives/185#comments</comments>
		<pubDate>Sat, 29 Sep 2007 16:00:10 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[程式筆記]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.linym.net/archives/185</guid>
		<description><![CDATA[今天有個學妹問我一個 C 程式的問題：下面程式的結果為何？ #include &#60;stdio.h&#62; int main(void) { int age = 20; printf(&#34;You are now %d, and will be %d in one year&#34;, age, age++); return 0 ; } 自認觀念還不錯的我直接就回答「20, 20」。但沒想到實際跑的答案竟然是「21, 20」，這真是出乎意料的結果啊！ 馬上另外測試了其他有 printf 函式的語言，如 Java、PHP，結果也都是正確的「20, 20」，所以不知道是 C printf 的 bug 還是什麼原因，希望有人能解答。 請看：C 語言中 printf 的問題(續)]]></description>
			<content:encoded><![CDATA[<p>今天有個學妹問我一個 C 程式的問題：下面程式的結果為何？</p>
<pre title="code" class="php">

#include &lt;stdio.h&gt;
int main(void)
{
    int age = 20;
    printf(&quot;You are now %d, and will be %d in one year&quot;, age, age++);
    return 0 ;
}
</pre>
<p>自認觀念還不錯的我直接就回答「20, 20」。但沒想到實際跑的答案竟然是「21, 20」，這真是出乎意料的結果啊！</p>
<p>馬上另外測試了其他有 printf 函式的語言，如 Java、PHP，結果也都是正確的「20, 20」，所以不知道是 C printf 的 bug 還是什麼原因，希望有人能解答。</p>
<p>請看：<a href="http://blog.linym.net/archives/186">C 語言中 printf 的問題(續)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/185/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>JavaScript 讀取外部文字檔</title>
		<link>http://blog.linym.net/archives/165</link>
		<comments>http://blog.linym.net/archives/165#comments</comments>
		<pubDate>Thu, 02 Aug 2007 17:40:43 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Other]]></category>
		<category><![CDATA[程式筆記]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.linym.net/archives/165</guid>
		<description><![CDATA[想要利用 JavaScript 來讀取一個檔案內容，搜尋到的方法很多都是用 ActiveX 物件來達成，這樣缺點就只能 IE Only 了。不過後來發現其實用 Ajax 就可以達成了。 搭配 JQuery 使用： $.get(&#039;content.txt&#039;, function(data){ alert(data); }); 這裡透過 Ajax 發出 GET Request 到 content.txt，就會直接將檔案的內容傳回輸出，很簡單吧^^ 但是由於 Ajax 考慮到安全性，所以只能作用在同網域底下。如果要讀的檔案是遠端主機上的呢？這時可以利用其他程式當作中間人，例如透過 PHP 去取得不同網域下的檔案。 JS 內容: $.get(&#039;readfile.php&#039;, function(data){ alert(data); }); PHP 內容: &#60;?php echo file_get_contents(&#34;http://aaa.com.tw/content.txt&#34;); ?&#62;]]></description>
			<content:encoded><![CDATA[<p>想要利用 JavaScript 來讀取一個檔案內容，搜尋到的方法很多都是用 ActiveX 物件來達成，這樣缺點就只能 IE Only 了。不過後來發現其實用 Ajax 就可以達成了。</p>
<p>搭配 <a href="http://jquery.com/" target="_blank">JQuery</a> 使用：</p>
<pre title="code" class="javascript">

$.get(&#039;content.txt&#039;, function(data){
	alert(data);
});
</pre>
<p>這裡透過 Ajax 發出 GET Request 到 content.txt，就會直接將檔案的內容傳回輸出，很簡單吧^^</p>
<p>但是由於 Ajax 考慮到安全性，所以只能作用在同網域底下。如果要讀的檔案是遠端主機上的呢？這時可以利用其他程式當作中間人，例如透過 PHP 去取得不同網域下的檔案。</p>
<p><strong>JS 內容:</strong></p>
<pre title="code" class="javascript">

$.get(&#039;readfile.php&#039;, function(data){
	alert(data);
});
</pre>
<p><strong>PHP 內容:</strong></p>
<pre title="code" class="php">

&lt;?php
echo file_get_contents(&quot;http://aaa.com.tw/content.txt&quot;);
?&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/165/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>UrMap API 基本應用</title>
		<link>http://blog.linym.net/archives/164</link>
		<comments>http://blog.linym.net/archives/164#comments</comments>
		<pubDate>Thu, 02 Aug 2007 17:13:14 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Other]]></category>
		<category><![CDATA[程式筆記]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[UrMap]]></category>
		<category><![CDATA[Web 2.0]]></category>

		<guid isPermaLink="false">http://blog.linym.net/archives/164</guid>
		<description><![CDATA[UrMap 和 Google Map 都是很不錯的線上圖資系統，不過由於 UrMap 是由國人開發維護的，所以目前還是比較適合台灣人使用，尤其在查詢街道方面比 Google 精確。 而這兩套系統也都有釋出各自的 API，讓我們可以做許多的應用，這次幫同學的專題作一個簡單的 Demo，功能是假設有個程式會透過 GPS 接收器取得座標，然後將座標寫入檔案，Web Server 網頁則會定時讀取及更新地圖，標示出目標現在的位置，算是一個基本應用囉！ 首先不管是 UrMap API 還是 Google Map API，使用之前都要先申請授權碼(Key)，並且將它加入您的網頁裡面，所以只能在您登錄的網址顯示地圖。 接下來顯示地圖部份請參考 Demo 網頁原始碼，其他功能在 API 說明文件都寫得很詳盡。]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.urmap.com/" target="_blank">UrMap</a> 和 Google Map 都是很不錯的線上圖資系統，不過由於 UrMap 是由國人開發維護的，所以目前還是比較適合台灣人使用，尤其在查詢街道方面比 Google 精確。</p>
<p>而這兩套系統也都有釋出各自的 API，讓我們可以做許多的應用，這次幫同學的專題作一個簡單的 <a href="http://map.linym.net/" target="_blank">Demo</a>，功能是假設有個程式會透過 GPS 接收器取得座標，然後將座標寫入檔案，Web Server 網頁則會定時讀取及更新地圖，標示出目標現在的位置，算是一個基本應用囉！</p>
<p>首先不管是 <a href="http://www.urmap.com/SearchEngine/api/" target="_blank">UrMap API</a> 還是 <a href="http://www.google.com/apis/maps/" target="_blank">Google Map API</a>，使用之前都要先申請授權碼(Key)，並且將它加入您的網頁裡面，所以只能在您登錄的網址顯示地圖。</p>
<p>接下來顯示地圖部份請參考 <a href="http://map.linym.net/" target="_blank">Demo</a> 網頁原始碼，其他功能在 API 說明文件都寫得很詳盡。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/164/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CodeIgniter - PHP Framework</title>
		<link>http://blog.linym.net/archives/162</link>
		<comments>http://blog.linym.net/archives/162#comments</comments>
		<pubDate>Sat, 28 Jul 2007 12:22:55 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[程式筆記]]></category>
		<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.linym.net/archives/162</guid>
		<description><![CDATA[最近在 PTT 的 PHP 版看到有人提到了這個 PHP Framework - CodeIgniter，當然也好奇的稍微瞭解一下囉！ 目前 PHP 最受矚目的應該是剛釋出正式版的 Zend Framework 及 CakePHP 了，都是很不錯，但是 Zend 僅支援 PHP5，現在還有不少學校、企業都還沒升級；而 CakePHP 則學習曲線稍長，想馬上用來開發小型應用效果不一定會比較好。 這時可以試試 CodeIgniter，應該也是不錯的選擇。沒有很龐大複雜的類別庫，有基本的 MVC 模式，也有所謂的 Helpers 幫你完成一些常用的功能，官方手冊也寫的很清楚，算是滿容易上手的一個 Framework。]]></description>
			<content:encoded><![CDATA[<p>最近在 PTT 的 PHP 版看到有人提到了這個 PHP Framework - <a href="http://codeigniter.com/" target="_blank">CodeIgniter</a>，當然也好奇的稍微瞭解一下囉！</p>
<p>目前 PHP 最受矚目的應該是剛釋出正式版的 <a href="http://framework.zend.com/" target="_blank">Zend Framework</a> 及 <a href="http://www.cakephp.org/" target="_blank">CakePHP</a> 了，都是很不錯，但是 Zend 僅支援 PHP5，現在還有不少學校、企業都還沒升級；而 CakePHP 則學習曲線稍長，想馬上用來開發小型應用效果不一定會比較好。</p>
<p>這時可以試試 <a href="http://codeigniter.com/" target="_blank">CodeIgniter</a>，應該也是不錯的選擇。沒有很龐大複雜的類別庫，有基本的 MVC 模式，也有所謂的 Helpers 幫你完成一些常用的功能，官方手冊也寫的很清楚，算是滿容易上手的一個 Framework。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/162/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>PHP 4 壽命已近</title>
		<link>http://blog.linym.net/archives/159</link>
		<comments>http://blog.linym.net/archives/159#comments</comments>
		<pubDate>Fri, 13 Jul 2007 13:29:37 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[資訊新聞]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[新聞]]></category>

		<guid isPermaLink="false">http://blog.linym.net/archives/159</guid>
		<description><![CDATA[PHP 官方今天正式公告了 PHP4 將在年底停止開發。這應該算是個好消息吧，算一算 PHP5 釋出已經三、四年了，到現在很多主機還是只用 PHP4，導致 PHP 程式人員不得不使用相容 PHP4 的寫法，現在 PHP4 壽命終止，可以讓更多人真正進入 PHP5 的世界，使 PHP 社群更進一步。 PHP 4 end of life announcement [13-Jul-2007] Today it is exactly three years ago since PHP 5 has been released. In those three years it has seen many improvements over PHP 4. PHP 5 is fast, stable &#038; [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.php.net/">PHP 官方</a>今天正式公告了 PHP4 將在年底停止開發。這應該算是個好消息吧，算一算 PHP5 釋出已經三、四年了，到現在很多主機還是只用 PHP4，導致 PHP 程式人員不得不使用相容 PHP4 的寫法，現在 PHP4 壽命終止，可以讓更多人真正進入 PHP5 的世界，使 PHP 社群更進一步。</p>
<blockquote><p>
<strong>PHP 4 end of life announcement</strong><br />
[13-Jul-2007]</p>
<p>Today it is exactly three years ago since PHP 5 has been released. In those three years it has seen many improvements over PHP 4. PHP 5 is fast, stable &#038; production-ready and as PHP 6 is on the way, PHP 4 will be discontinued.</p>
<p>The PHP development team hereby announces that support for PHP 4 will continue until the end of this year only. After 2007-12-31 there will be no more releases of PHP 4.4. We will continue to make critical security fixes available on a case-by-case basis until 2008-08-08. Please use the rest of this year to make your application suitable to run on PHP 5.</p>
<p>For documentation on migration for PHP 4 to PHP 5, we would like to point you to our migration guide. There is additional information available in the PHP 5.0 to PHP 5.1 and PHP 5.1 to PHP 5.2 migration guides as well.</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/159/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>可攜式 APM 網頁伺服器</title>
		<link>http://blog.linym.net/archives/127</link>
		<comments>http://blog.linym.net/archives/127#comments</comments>
		<pubDate>Sun, 03 Jun 2007 02:21:57 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[系統筆記]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Portable]]></category>
		<category><![CDATA[伺服器]]></category>

		<guid isPermaLink="false">http://lym.fyman.idv.tw/blog/archives/127</guid>
		<description><![CDATA[本文已移至新分頁：http://blog.linym.net/portableapm]]></description>
			<content:encoded><![CDATA[<p>本文已移至新分頁：<a href="http://blog.linym.net/portableapm">http://blog.linym.net/portableapm</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/127/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Cheat Sheet 速查表大集合</title>
		<link>http://blog.linym.net/archives/143</link>
		<comments>http://blog.linym.net/archives/143#comments</comments>
		<pubDate>Wed, 23 May 2007 09:13:31 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[好書好站]]></category>
		<category><![CDATA[程式筆記]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[手冊]]></category>
		<category><![CDATA[程式設計]]></category>

		<guid isPermaLink="false">http://lym.fyman.idv.tw/blog/archives/143</guid>
		<description><![CDATA[國外的有心人士喜歡把一些電腦經常用到的，例如程式設計，快捷鍵等，整理成一張 Cheat Sheet，有點類似小抄的東西，方便查閱，而且都做的相當精美，就算對其中的技術不熟當成收藏也不錯 XD 底下這個網站就收集了很多 Cheat Sheet，都有 PNG 及 PDF 格式，趕快去印一張放在桌上吧! Cheat Sheet 大集合 另外附上 WoW 魔獸世界的 Cheat Sheet]]></description>
			<content:encoded><![CDATA[<p>國外的有心人士喜歡把一些電腦經常用到的，例如程式設計，快捷鍵等，整理成一張 Cheat Sheet，有點類似小抄的東西，方便查閱，而且都做的相當精美，就算對其中的技術不熟當成收藏也不錯 XD<br />
底下這個網站就收集了很多 Cheat Sheet，都有 PNG 及 PDF 格式，趕快去印一張放在桌上吧!</p>
<p><a href="http://www.smashingmagazine.com/2006/10/30/cheat-sheet-round-up-ajax-css-latex-ruby/" target="_blank">Cheat Sheet 大集合</a></p>
<p>另外附上 WoW 魔獸世界的 <a href="http://www.ilovejackdaniels.com/cheat-sheets/world-of-warcraft-cheat-sheet/" target="_blank">Cheat Sheet</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/143/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>jQuery Plugin</title>
		<link>http://blog.linym.net/archives/135</link>
		<comments>http://blog.linym.net/archives/135#comments</comments>
		<pubDate>Wed, 09 May 2007 17:44:50 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[程式筆記]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Web 2.0]]></category>

		<guid isPermaLink="false">http://lym.fyman.idv.tw/blog/archives/135</guid>
		<description><![CDATA[jQuery 是個不錯的 JavaScript library，可以省略不少繁瑣的細節，且檔案大小又不大，最近都用它來開發網頁。同時也注意到了一些好用的 Plugin，主要是應用在 Ajax 上，有現成又好用的就不用再自己寫囉！ Validation 可用來做即時欄位驗證 History 無法回上一頁算是 Ajax 的一項缺點，用這個 plugin 可以做出回上頁的效果 jEditable 提供就地編輯(Edit In Place)的功能 ajaxFileUpload 利用隱藏 iframe 達到不換頁上傳檔案 Ajax File Manager 加強 tinymce 這個線上編輯器，可瀏覽檔案及上傳檔案 Interface 提供非常大量的動態效果，必試。 Form 使用 Ajax 送出表單資料]]></description>
			<content:encoded><![CDATA[<p><a href="http://jquery.com/">jQuery</a> 是個不錯的 JavaScript library，可以省略不少繁瑣的細節，且檔案大小又不大，最近都用它來開發網頁。同時也注意到了一些好用的 Plugin，主要是應用在 Ajax 上，有現成又好用的就不用再自己寫囉！</p>
<ol>
<li><a href="http://bassistance.de/jquery-plugins/jquery-plugin-validation/">Validation</a><br />
可用來做即時欄位驗證</li>
<li><a href="http://www.mikage.to/jquery/jquery_history.html">History</a><br />
無法回上一頁算是 Ajax 的一項缺點，用這個 plugin 可以做出回上頁的效果</li>
<li><a href="http://www.appelsiini.net/~tuupola/javascript/jEditable/">jEditable</a><br />
提供就地編輯(Edit In Place)的功能</li>
<li><a href="http://www.phpletter.com/Demo/AjaxFileUpload-Demo/">ajaxFileUpload</a><br />
利用隱藏 iframe 達到不換頁上傳檔案</li>
<li><a href="http://www.phpletter.com/Demo/Ajax-File--Manager/">Ajax File Manager</a><br />
加強 tinymce 這個線上編輯器，可瀏覽檔案及上傳檔案</li>
<li><a href="http://interface.eyecon.ro/">Interface</a><br />
提供非常大量的動態效果，必試。</li>
<li><a href="http://www.malsup.com/jquery/form/">Form</a><br />
使用 Ajax 送出表單資料</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/135/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OpenGL-海龜作圖法</title>
		<link>http://blog.linym.net/archives/116</link>
		<comments>http://blog.linym.net/archives/116#comments</comments>
		<pubDate>Tue, 16 Jan 2007 04:22:38 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[程式筆記]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[海龜作圖]]></category>

		<guid isPermaLink="false">http://lym.fyman.idv.tw/blog/archives/116</guid>
		<description><![CDATA[海龜作圖法(Turtle Graphics)，意思是模仿海龜移動的方式，只能前進及左右轉，而將海龜的尾巴當作畫筆，可以放下及抬起。 本範例為二維空間，使用 OpenGL 搭配 C++ 實做。 程式功能介紹： 1、由 turtle.txt 檔案讀入作圖指令。 2、INIT - 設定海龜初始位置。(x 軸, y 軸, 龜頭角度) 3、PEN - 設定尾巴狀態。(0 抬起 / 1放下) 4、FW - 海龜向前移動。(移動長度) 5、RIGHT - 海龜右轉角度。(角度) 6、LEFT - 海龜左轉角度。(角度) #include &#60;iostream&#62; #include &#60;fstream&#62; #include &#60;cstring&#62; #include &#60;cmath&#62; #include &#60;GL/glut.h&#62; using namespace std; const GLfloat PI = 3.141593; class Turtle { private: [...]]]></description>
			<content:encoded><![CDATA[<p>海龜作圖法(Turtle Graphics)，意思是模仿海龜移動的方式，只能前進及左右轉，而將海龜的尾巴當作畫筆，可以放下及抬起。<br />
本範例為二維空間，使用 OpenGL 搭配 C++ 實做。</p>
<p><strong>程式功能介紹：</strong><br />
1、由 turtle.txt 檔案讀入作圖指令。<br />
2、INIT - 設定海龜初始位置。(x 軸, y 軸, 龜頭角度)<br />
3、PEN - 設定尾巴狀態。(0 抬起 / 1放下)<br />
4、FW - 海龜向前移動。(移動長度)<br />
5、RIGHT - 海龜右轉角度。(角度)<br />
6、LEFT - 海龜左轉角度。(角度)</p>
<pre title="code" class="cpp">

#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;cstring&gt;
#include &lt;cmath&gt;
#include &lt;GL/glut.h&gt;
using namespace std;

const GLfloat PI = 3.141593;

class Turtle {
private:
    bool penStatus, a;
    GLfloat x1, y1, x2, y2; //座標
    GLfloat cAngle; //角度
public:
    Turtle() //constractor
    {
        penStatus = 0;
        x1 = y1 = x2 = y2 = 0.0;
        cAngle = 0.0;
        a = 0;
    }

    /* 設定海龜位置 */
    void InitPoint(GLfloat x, GLfloat y, GLfloat angle)
    {
        x1 = x; y1 = y; cAngle = angle; a = 1;
        if (penStatus) //如果 pen down 應該畫出一點
        {
            glBegin(GL_POINTS);
                glVertex2f(x, y);
            glEnd();
        }
    }
    /* 海龜向前移動 */
    void forward(GLfloat L)
    {
        x2 = x1 + L * cos(cAngle*PI/180);
        y2 = y1 + L * sin(cAngle*PI/180);

        if (penStatus)
        {
            glBegin(GL_LINES);
                glVertex2f(x1, y1);
                glVertex2f(x2, y2);
            glEnd();
        }

        x1 = x2; y1 = y2;
    }
    /* 海龜右轉角度 */
    void right(GLfloat angle)
    {
        cAngle = (a) ? cAngle - angle : angle;
        a = 1;
    }
    /* 海龜左轉角度 */
    void left(GLfloat angle)
    {
        cAngle = (a) ? cAngle + angle : angle;
        a = 1;
    }
    /* 設定畫筆狀態(0 up/1 down) */
    void setPen(bool value)
    {
        penStatus = value;
		if (value) //pen down 畫出一點
		{
			glBegin(GL_POINTS);
				glVertex2f(x1, y1);
			glEnd();
		}
    }

};

void display(void)
{
    glClear(GL_COLOR_BUFFER_BIT);  /*clear the window */

    char cmd[10];
    float x, y, angle;
    bool p;
    ifstream fp(&quot;turtle.txt&quot;);
    Turtle t;

    while (!fp.eof())
    {
        fp &gt;&gt; cmd;
        if (!strcmp(cmd, &quot;INIT&quot;)) {
            fp &gt;&gt; x &gt;&gt; y &gt;&gt; angle;
            t.InitPoint(x, y, angle);
        } else if (!strcmp(cmd, &quot;FW&quot;)) {
            fp &gt;&gt; x;
            t.forward(x);
        } else if (!strcmp(cmd, &quot;RIGHT&quot;)) {
            fp &gt;&gt; x;
            t.right(x);
        } else if (!strcmp(cmd, &quot;LEFT&quot;)) {
            fp &gt;&gt; x;
            t.left(x);
        } else if (!strcmp(cmd, &quot;PEN&quot;)) {
            fp &gt;&gt; p;
            t.setPen(p);
        }
    }

    glFlush(); /* clear buffers */
}

int main(int argc, char** argv)
{

/* Standard GLUT initialization */
    glutInit(&amp;argc, argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); /* default, not needed */
    glutInitWindowSize(500, 500); /* 500 x 500 pixel window */
    glutInitWindowPosition(0, 0); /* place window top left on display */
    glutCreateWindow(&quot;Turtle Graphics&quot;); /* window title */
    glutDisplayFunc(display); /* display callback invoked when window opened */

/* attributes */
    glClearColor(1.0, 1.0, 1.0, 1.0); /* white background */
    glColor3f(1.0, 0.0, 0.0); /* draw in red */
/* set up viewing */
/* 500 x 500 window with origin lower left */
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0.0, 500.0, 0.0, 500.0);
    glMatrixMode(GL_MODELVIEW);

    glutMainLoop(); /* enter event loop */

    return 0;
}
</pre>
<p><a href="http://blog.linym.net/wp-content/uploads/2007/02/turtle.txt" title="turtle.txt">turtle.txt</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/116/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>解決版面被撐開的方法</title>
		<link>http://blog.linym.net/archives/110</link>
		<comments>http://blog.linym.net/archives/110#comments</comments>
		<pubDate>Sat, 22 Jul 2006 14:58:53 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[程式筆記]]></category>
		<category><![CDATA[網頁設計]]></category>

		<guid isPermaLink="false">http://lym.fyman.idv.tw/blog/archives/110</guid>
		<description><![CDATA[寫網頁程式經常會遇到版面被撐開的情形，例如有人輸入一長串的網址，或是沒有空格的英文+數字，這些都會造成瀏覽器無法自動斷行導致版面被撐開，而解決方法除了用程式強制斷行之外，IE 中可以用 word-break:break-all 的 CSS 來解決，但是比較好的方式可以參考 jon 所寫的這篇，利用 wbr tag 來處理‧ 文章：PHP: 文字過長加入 WBR tag function]]></description>
			<content:encoded><![CDATA[<p>寫網頁程式經常會遇到版面被撐開的情形，例如有人輸入一長串的網址，或是沒有空格的英文+數字，這些都會造成瀏覽器無法自動斷行導致版面被撐開，而解決方法除了用程式強制斷行之外，IE 中可以用 word-break:break-all 的 CSS 來解決，但是比較好的方式可以參考 jon 所寫的這篇，利用 wbr tag 來處理‧</p>
<p>文章：<a href="http://plog.longwin.com.tw/post/1/418">PHP: 文字過長加入 WBR tag function</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/110/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>幾個 Text Database</title>
		<link>http://blog.linym.net/archives/104</link>
		<comments>http://blog.linym.net/archives/104#comments</comments>
		<pubDate>Sat, 03 Jun 2006 08:43:16 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[程式筆記]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[資料庫]]></category>

		<guid isPermaLink="false">http://lym.fyman.idv.tw/blog/archives/104</guid>
		<description><![CDATA[雖然 PHP 搭配 MySQL 來開發程式可以較快速又方便管理，但多少會遇到一些主機無法支援如 MySQL 等資料庫的 case，只好使用文字檔來儲存資料，不過因為沒有欄位及索引這些東西，開發起來就會麻煩許多，所幸就有人寫出 text base 的資料庫程式，讓我們使用純文字檔存取資料時，可以較接近資料庫操作，加快開發速度。 ‧SQLite 這套可以說是目前最火紅的，一堆語言都有支援它，PHP 當然也不例外，可使用 SQL 語法操作，PEAR::DB 也有支援。 只是需要載入 extension，所以要是主機沒有安裝或開啟，就只能以 shell 執行 SQLite 的執行檔來操作了，不過也失去資料庫的特性了。 ‧PHP Text DB API 這套是 PHP class，可以使用 SQL 語法、PEAR::DB 的用法，也不用另外載入 extension，並且有包含小型的 GUI 管理程式，非常值得一試。 ‧PHP Text DataBase API 這套是對岸的人士寫的，只要一個 class 檔就可以使用了，雖然它不支援 SQL 語法，但是簡單易用，大概花個 10 分鐘看完 manual 及範例就可以上手了，非常適合開發簡單的小程式。 如果有找到更好用的，歡迎來推薦一下哦！]]></description>
			<content:encoded><![CDATA[<p>雖然 PHP 搭配 MySQL 來開發程式可以較快速又方便管理，但多少會遇到一些主機無法支援如 MySQL 等資料庫的 case，只好使用文字檔來儲存資料，不過因為沒有欄位及索引這些東西，開發起來就會麻煩許多，所幸就有人寫出 text base 的資料庫程式，讓我們使用純文字檔存取資料時，可以較接近資料庫操作，加快開發速度。</p>
<p><a href="http://www.sqlite.org/">‧SQLite</a><br />
這套可以說是目前最火紅的，一堆語言都有支援它，PHP 當然也不例外，可使用 SQL 語法操作，PEAR::DB 也有支援。<br />
只是需要載入 extension，所以要是主機沒有安裝或開啟，就只能以 shell 執行 SQLite 的執行檔來操作了，不過也失去資料庫的特性了。</p>
<p><a href="http://www.c-worker.ch/txtdbapi/index_eng.php">‧PHP Text DB API</a><br />
這套是 PHP class，可以使用 SQL 語法、PEAR::DB 的用法，也不用另外載入 extension，並且有包含小型的 GUI 管理程式，非常值得一試。</p>
<p><a href="http://www.3ants.org/dev/txtdb/">‧PHP Text DataBase API</a><br />
這套是對岸的人士寫的，只要一個 class 檔就可以使用了，雖然它不支援 SQL 語法，但是簡單易用，大概花個 10 分鐘看完 manual 及範例就可以上手了，非常適合開發簡單的小程式。</p>
<p>如果有找到更好用的，歡迎來推薦一下哦！</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/104/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>[PHP] 計算頁面執行時間</title>
		<link>http://blog.linym.net/archives/103</link>
		<comments>http://blog.linym.net/archives/103#comments</comments>
		<pubDate>Sun, 21 May 2006 15:35:28 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[程式筆記]]></category>

		<guid isPermaLink="false">http://lym.fyman.idv.tw/blog/archives/103</guid>
		<description><![CDATA[計算頁面執行時間的方法很簡單，只要抓兩個 time 來相減就好了。而 PEAR 中也有個專屬的程式庫叫「Benchmark」，功能很完整，還可以分段計時，不過為了計算個時間還要載入整個 PEAR::Benchmark，實在不太方便，所以將它做了簡化版本。 ‧Timer Class for PHP5 ‧Timer Class for PHP4 Example： $timer = new Timer(); $timer-&#62;start(); // 設定開始標籤 for ($i = 0; $i &#60; 10000; $i++); $timer-&#62;stop(); // 設定結束標籤 $timer-&#62;display();]]></description>
			<content:encoded><![CDATA[<p>計算頁面執行時間的方法很簡單，只要抓兩個 time 來相減就好了。而 PEAR 中也有個專屬的程式庫叫「Benchmark」，功能很完整，還可以分段計時，不過為了計算個時間還要載入整個 PEAR::Benchmark，實在不太方便，所以將它做了簡化版本。</p>
<p>‧<a href="http://blog.linym.net/demo/timer/Timer_PHP5.phps">Timer Class for PHP5</a><br />
‧<a href="http://blog.linym.net/demo/timer/Timer_PHP4.phps">Timer Class for PHP4</a></p>
<p>Example：</p>
<pre title="code" class="php">

$timer = new Timer();
$timer-&gt;start(); // 設定開始標籤
for ($i = 0; $i &lt; 10000; $i++);
$timer-&gt;stop(); // 設定結束標籤
$timer-&gt;display();
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/103/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>[Ajax] 實作 Gmail 的載入訊息</title>
		<link>http://blog.linym.net/archives/94</link>
		<comments>http://blog.linym.net/archives/94#comments</comments>
		<pubDate>Tue, 02 May 2006 10:48:42 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[程式筆記]]></category>
		<category><![CDATA[Gmail]]></category>
		<category><![CDATA[Web 2.0]]></category>

		<guid isPermaLink="false">http://lym.fyman.idv.tw/blog/archives/94</guid>
		<description><![CDATA[進入 Gmail、Calendar 等 Google 的服務，時常會看到右上角有個紅底白字的「載入中...」，拿來當第一個 Ajax 的練習。 基本作法就是利用一個 DIV 區塊，預設為不顯示，等到呼叫 JavaScript 建立 XMLHttpRequest 時，將 DIV 區塊設為顯示，最後等伺服器後端傳回訊息時再隱藏區塊即可。這個範例是使用者輸入訊息，由 PHP 處理並顛倒字串印出。 Demo 網頁部分： &#60;!DOCTYPE html PUBLIC &#34;-//W3C//DTD XHTML 1.0 Transitional//EN&#34; &#34;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&#34;&#62; &#60;html xmlns=&#34;http://www.w3.org/1999/xhtml&#34;&#62; &#60;head&#62; &#60;meta http-equiv=&#34;Content-Type&#34; content=&#34;text/html; charset=big5&#34; /&#62; &#60;title&#62;Ajax Test&#60;/title&#62; &#60;script type=&#34;text/javascript&#34;&#62; var ajax; function createHttpRequest() { if (window.ActiveXObject) { try { return new ActiveXObject(&#34;Msxml2.XMLHTTP&#34;); } catch [...]]]></description>
			<content:encoded><![CDATA[<p>進入 Gmail、Calendar 等 Google 的服務，時常會看到右上角有個紅底白字的「載入中...」，拿來當第一個 Ajax 的練習。<br />
基本作法就是利用一個 DIV 區塊，預設為不顯示，等到呼叫 JavaScript 建立 XMLHttpRequest 時，將 DIV 區塊設為顯示，最後等伺服器後端傳回訊息時再隱藏區塊即可。這個範例是使用者輸入訊息，由 PHP 處理並顛倒字串印出。<br />
<a href="http://blog.linym.net/demo/ajax/echo.htm" target="_blank">Demo</a><br />
網頁部分：</p>
<pre title="code" class="html">

&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=big5&quot; /&gt;
&lt;title&gt;Ajax Test&lt;/title&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
var ajax;

function createHttpRequest() {
    if (window.ActiveXObject) {
        try {
            return new ActiveXObject(&quot;Msxml2.XMLHTTP&quot;);
        } catch (e) {
            try {
                return new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;);
            } catch (e2) {
                return null;
            }
        }
    } else if (window.XMLHttpRequest) {
        return new XMLHttpRequest();
    } else {
        return null;
    }
}

function ajaxSendRequest(url) {
	var msg = document.getElementById(&#039;msg&#039;).value;
    document.getElementById(&#039;loading&#039;).style.display = &quot;block&quot;;
    ajax = createHttpRequest();
    ajax.onreadystatechange = showResult;
    ajax.open(&quot;GET&quot;, url + &#039;?message=&#039; + msg);
    ajax.send(&quot;&quot;);
}

function showResult() {
    if (ajax.readyState == 4 &amp;&amp; ajax.status == 200) {
        document.getElementById(&#039;loading&#039;).style.display = &quot;none&quot;;
		document.getElementById(&#039;echo_msg&#039;).innerHTML = ajax.responseText;
    }
}
&lt;/script&gt;
&lt;style type=&quot;text/css&quot;&gt;
#loading {
	position: absolute;
	width: 50px;
	height: 20px;
	line-height: 20px;
	top: 5px;
	right: 5px;
	font-size: 12px;
	background-color: #C44;
	color: #FFF;
	text-align: center;
}
&lt;/style&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;div id=&quot;loading&quot; style=&quot;display:none&quot;&gt;載入中...&lt;/div&gt;
請輸入英文訊息：&lt;input type=&quot;text&quot; id=&quot;msg&quot; /&gt;&lt;br /&gt;
&lt;div id=&quot;echo_msg&quot;&gt;&lt;/div&gt;
&lt;input type=&quot;submit&quot; id=&quot;Submit&quot; value=&quot;送出&quot; onclick=&quot;ajaxSendRequest(&#039;echo.php&#039;)&quot; /&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>PHP 部分：</p>
<pre title="code" class="php">

&lt;?php
$message = $_GET[&#039;message&#039;];
sleep(2); // 睡一下吧,不然&quot;載入中&quot;會太快消失
echo strrev($message);
?&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/94/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

