<?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; PHP</title>
	<atom:link href="http://blog.linym.net/archives/category/program/php/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>修改 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>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>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>建立網頁縮圖(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>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>解決版面被撐開的方法</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>[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>[PHP] 使用 ImageMagick 製作縮圖</title>
		<link>http://blog.linym.net/archives/84</link>
		<comments>http://blog.linym.net/archives/84#comments</comments>
		<pubDate>Sat, 15 Apr 2006 09:27:05 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[程式筆記]]></category>
		<category><![CDATA[ImageMagick]]></category>
		<category><![CDATA[縮圖]]></category>

		<guid isPermaLink="false">http://lym.fyman.idv.tw/blog/archives/84</guid>
		<description><![CDATA[ImageMagick 是一套功能多且強大的圖片處理工具，可以用來製作縮圖、轉換影像格式等，和 GD 比較，ImageMagick 製作的縮圖顯的清晰準確，不過要使用它需要另外安裝，而且是在 command line 執行的，所以 PHP 就可以用 shell_exec() 或 exec() 來呼叫它囉！ // 呼叫 ImageMagic 的 convert shell_exec(&#34;/usr/bin/convert -geometry 200x200 big_img.jpg small_img.jpg&#34;); 這段示範了 ImageMagick 的縮圖功能，依照原圖比例縮小(最大 200x200)。 有關其他更詳細的用法，可直接上 ImageMagick 網站查詢。]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.imagemagick.org/">ImageMagick</a> 是一套功能多且強大的圖片處理工具，可以用來製作縮圖、轉換影像格式等，和 GD 比較，ImageMagick 製作的縮圖顯的清晰準確，不過要使用它需要另外安裝，而且是在 command line 執行的，所以 PHP 就可以用 shell_exec() 或 exec() 來呼叫它囉！</p>
<pre title="code" class="php">

// 呼叫 ImageMagic 的 convert
shell_exec(&quot;/usr/bin/convert -geometry 200x200 big_img.jpg small_img.jpg&quot;);
</pre>
<p>這段示範了 ImageMagick 的縮圖功能，依照原圖比例縮小(最大 200x200)。<br />
有關其他更詳細的用法，可直接上 <a href="http://www.imagemagick.org/">ImageMagick</a> 網站查詢。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/84/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>PHP 取得鍵盤輸入</title>
		<link>http://blog.linym.net/archives/75</link>
		<comments>http://blog.linym.net/archives/75#comments</comments>
		<pubDate>Thu, 09 Mar 2006 04:27:31 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[程式筆記]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://lym.fyman.idv.tw/blog/archives/75</guid>
		<description><![CDATA[最近學校老師教利用 Perl 寫網路程式，是由命令列執行的，於是也想使用較熟悉的 PHP 看是否能完成相同的功能，第一個遇到的問題就是怎麼由鍵盤輸入字元囉！於是翻了許久的 PHP 官方手冊，終於找到方法了。 // 取得鍵盤輸入 function stdin($length = 255) { if (!isset($GLOBALS[&#039;StdinPointer&#039;])) $GLOBALS[&#039;StdinPointer&#039;] = fopen(&#039;php://stdin&#039;, &#039;r&#039;); $intput = fgets($GLOBALS[&#039;StdinPointer&#039;], $length); return trim($intput); } 官方手冊：http://tw2.php.net/manual/en/function.fopen.php#14426]]></description>
			<content:encoded><![CDATA[<p>最近學校老師教利用 Perl 寫網路程式，是由命令列執行的，於是也想使用較熟悉的 PHP 看是否能完成相同的功能，第一個遇到的問題就是怎麼由鍵盤輸入字元囉！於是翻了許久的 PHP 官方手冊，終於找到方法了。</p>
<pre title="code" class="php">

// 取得鍵盤輸入
function stdin($length = 255) {
    if (!isset($GLOBALS[&#039;StdinPointer&#039;]))
        $GLOBALS[&#039;StdinPointer&#039;] = fopen(&#039;php://stdin&#039;, &#039;r&#039;);
    $intput = fgets($GLOBALS[&#039;StdinPointer&#039;], $length);
    return trim($intput);
}
</pre>
<p>官方手冊：<a href="http://tw2.php.net/manual/en/function.fopen.php#14426">http://tw2.php.net/manual/en/function.fopen.php#14426</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/75/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[PHP] 解決 substr 擷取中文字時出現問號</title>
		<link>http://blog.linym.net/archives/74</link>
		<comments>http://blog.linym.net/archives/74#comments</comments>
		<pubDate>Sat, 04 Mar 2006 03:22:00 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[程式筆記]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://lym.fyman.idv.tw/blog/archives/74</guid>
		<description><![CDATA[PHP 有個擷取字串的函式 substr()，但是遇到中文字可就沒辦法正確擷取了，因為一個中文字在 BIG5 編碼是 2 byte，在 UTF-8 要 3 byte，如果擷取的字串剛好不到一個中文，那就會出現「?」之類的符號。所以提供一個解決方法，就是使用 mb_substr()，使用時必須先正確載入 PHP 的 mbstring 模組。 Example： &#60;?php $string = &#039;這是中文字&#039;; $string = mb_substr($string, 0, 4, &#039;BIG-5&#039;); echo $string; ?&#62; 這樣就會正確擷取到「這是中文」了。]]></description>
			<content:encoded><![CDATA[<p>PHP 有個擷取字串的函式 substr()，但是遇到中文字可就沒辦法正確擷取了，因為一個中文字在 BIG5 編碼是 2 byte，在 UTF-8 要 3 byte，如果擷取的字串剛好不到一個中文，那就會出現「?」之類的符號。所以提供一個解決方法，就是使用 mb_substr()，使用時必須先正確載入 PHP 的 mbstring 模組。</p>
<p>Example：</p>
<pre title="code" class="php">

&lt;?php
$string = &#039;這是中文字&#039;;
$string = mb_substr($string, 0, 4, &#039;BIG-5&#039;);
echo $string;
?&gt;
</pre>
<p>這樣就會正確擷取到「這是中文」了。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/74/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>使用 Smarty 製作交替顏色的表格</title>
		<link>http://blog.linym.net/archives/73</link>
		<comments>http://blog.linym.net/archives/73#comments</comments>
		<pubDate>Thu, 02 Mar 2006 15:56:38 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[程式筆記]]></category>
		<category><![CDATA[Smarty]]></category>

		<guid isPermaLink="false">http://lym.fyman.idv.tw/blog/archives/73</guid>
		<description><![CDATA[以往用 PHP 寫交替顏色表格可是需要寫一堆計算及判斷的程式碼，但是如果搭配 Smarty 樣版引擎就快速多了，只要在標籤加上 {cycle} 即可。 Example： {section name=rows loop=$data} &#60;tr bgcolor=&#34;{cycle values=&#34;#eeeeee,#d0d0d0&#34;}&#34;&#62; &#60;td&#62;{$data[rows]}&#60;/td&#62; &#60;/tr&#62; {/section} 官方手冊：http://smarty.php.net/manual/en/language.function.cycle.php]]></description>
			<content:encoded><![CDATA[<p>以往用 PHP 寫交替顏色表格可是需要寫一堆計算及判斷的程式碼，但是如果搭配 Smarty 樣版引擎就快速多了，只要在標籤加上 {cycle} 即可。</p>
<p>Example：</p>
<pre title="code" class="html">

{section name=rows loop=$data}
&lt;tr bgcolor=&quot;{cycle values=&quot;#eeeeee,#d0d0d0&quot;}&quot;&gt;
  &lt;td&gt;{$data[rows]}&lt;/td&gt;
&lt;/tr&gt;
{/section}
</pre>
<p>官方手冊：<a href="http://smarty.php.net/manual/en/language.function.cycle.php">http://smarty.php.net/manual/en/language.function.cycle.php</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/73/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[PHP] 可以使用 ini_set() 改變的項目</title>
		<link>http://blog.linym.net/archives/58</link>
		<comments>http://blog.linym.net/archives/58#comments</comments>
		<pubDate>Sun, 08 Jan 2006 02:42:31 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[程式筆記]]></category>
		<category><![CDATA[php.ini]]></category>

		<guid isPermaLink="false">http://lym.fyman.idv.tw/blog/archives/58</guid>
		<description><![CDATA[有時主機不能自己管理的時候，那就沒辦法更改 php.ini 這個設定檔，只能在程式裡利用 ini_set() 的方法暫時改變主機設定，但不是每個項目都可以用的。 http://tw.php.net/manual/en/ini.php#ini.list 只有 Changeable 欄位為 PHP_INI_USER 或 PHP_INI_ALL 才可以接受 ini_set() 設定。]]></description>
			<content:encoded><![CDATA[<p>有時主機不能自己管理的時候，那就沒辦法更改 php.ini 這個設定檔，只能在程式裡利用 ini_set() 的方法暫時改變主機設定，但不是每個項目都可以用的。</p>
<p><a href="http://tw.php.net/manual/en/ini.php#ini.list">http://tw.php.net/manual/en/ini.php#ini.list</a></p>
<p>只有 Changeable 欄位為 PHP_INI_USER 或 PHP_INI_ALL 才可以接受 ini_set() 設定。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/58/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>關於 setcookie() 及 session_start() 的錯誤</title>
		<link>http://blog.linym.net/archives/47</link>
		<comments>http://blog.linym.net/archives/47#comments</comments>
		<pubDate>Wed, 31 Aug 2005 11:00:00 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[程式筆記]]></category>
		<category><![CDATA[cookie]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[session]]></category>

		<guid isPermaLink="false">http://lym.fyman.idv.tw/blog/archives/47</guid>
		<description><![CDATA[PHP 設計人員都知道，使用 setcookie() 或 session_start() 函式之前不能有任何輸出，否則就會出現錯誤。這是因為這兩個函式呼叫後會將資訊加入 HTML 的標頭(Header)，而標頭都應該在 HTML 本體(body)輸出之前，如果呼叫這兩個函式時前面已經有東西輸出了，PHP 直譯器就會出現錯誤訊息。然而要檢查函式呼叫之前有沒有輸出是件非常麻煩的事情，因為 include 檔案內容裡的輸出都有可能造成錯誤，如果檔案數龐大，那檢查起來可是非常麻煩的，在此提供一個可以一勞永逸的方法： 開啟組態設定檔 php.ini ，將底下這項改為 On output_buffering = On 這樣 Web Server 在處理檔案時會將標頭全部處理完後，再輸出網頁內容，這樣網頁速度需多等千分之一秒，但卻可省去檢查程式碼的數千數萬秒，算是值得使用的功能囉！]]></description>
			<content:encoded><![CDATA[<p>PHP 設計人員都知道，使用 setcookie() 或 session_start() 函式之前不能有任何輸出，否則就會出現錯誤。這是因為這兩個函式呼叫後會將資訊加入 HTML 的標頭(Header)，而標頭都應該在 HTML 本體(body)輸出之前，如果呼叫這兩個函式時前面已經有東西輸出了，PHP 直譯器就會出現錯誤訊息。然而要檢查函式呼叫之前有沒有輸出是件非常麻煩的事情，因為 include 檔案內容裡的輸出都有可能造成錯誤，如果檔案數龐大，那檢查起來可是非常麻煩的，在此提供一個可以一勞永逸的方法：</p>
<p>開啟組態設定檔 php.ini ，將底下這項改為 On<br />
<strong>output_buffering = On</strong></p>
<p>這樣 Web Server 在處理檔案時會將標頭全部處理完後，再輸出網頁內容，這樣網頁速度需多等千分之一秒，但卻可省去檢查程式碼的數千數萬秒，算是值得使用的功能囉！</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/47/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>[PHP] 取得使用者真實 IP</title>
		<link>http://blog.linym.net/archives/31</link>
		<comments>http://blog.linym.net/archives/31#comments</comments>
		<pubDate>Thu, 12 May 2005 10:14:11 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[程式筆記]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://lym.fyman.idv.tw/blog/archives/31</guid>
		<description><![CDATA[一般在取得使用者 IP 都是利用 $_SERVER['REMOTE_ADDR'] 這個環境變數，但是此變數只會紀錄最後一個主機 IP，所以當使用者瀏覽器有設定 Proxy 時，就無法取得他的真實 IP。 這時可以使用另一個環境變數 $_SERVER['HTTP_X_FORWARDED_FOR'] ，它會紀錄所經過的主機 IP，但是只有在使用者有透過 Proxy 時才會產生，所以可以像以下這樣寫來取得使用者真實 IP。 &#60;?php if (empty($_SERVER[&#039;HTTP_X_FORWARDED_FOR&#039;])) { $myip = $_SERVER[&#039;REMOTE_ADDR&#039;]; } else { $myip = explode(&#039;,&#039;, $_SERVER[&#039;HTTP_X_FORWARDED_FOR&#039;]); $myip = $myip[0]; } echo $myip; ?&#62;]]></description>
			<content:encoded><![CDATA[<p>一般在取得使用者 IP 都是利用 $_SERVER['REMOTE_ADDR'] 這個環境變數，但是此變數只會紀錄最後一個主機 IP，所以當使用者瀏覽器有設定 Proxy 時，就無法取得他的真實 IP。<br />
這時可以使用另一個環境變數 $_SERVER['HTTP_X_FORWARDED_FOR'] ，它會紀錄所經過的主機 IP，但是只有在使用者有透過 Proxy 時才會產生，所以可以像以下這樣寫來取得使用者真實 IP。</p>
<pre title="code" class="php">

&lt;?php
if (empty($_SERVER[&#039;HTTP_X_FORWARDED_FOR&#039;])) {
    $myip = $_SERVER[&#039;REMOTE_ADDR&#039;];
} else {
    $myip = explode(&#039;,&#039;, $_SERVER[&#039;HTTP_X_FORWARDED_FOR&#039;]);
    $myip = $myip[0];
}
echo $myip;
?&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/31/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>[PHP] 顯示微秒時間</title>
		<link>http://blog.linym.net/archives/21</link>
		<comments>http://blog.linym.net/archives/21#comments</comments>
		<pubDate>Thu, 27 Jan 2005 14:57:02 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[程式筆記]]></category>

		<guid isPermaLink="false">http://lym.fyman.idv.tw/blog/archives/21</guid>
		<description><![CDATA[要讓 PHP 時間顯示到微秒(百萬分之一秒)，可使用 microtime() 函式。此函式會傳回目前的UNIX時間戳記及微秒數(中間以一個空格隔開)。 如：0.90625400 1106837367 //將UNIX時間戳記和微秒數分別存入陣列 $times = split(&#039; &#039;, microtime()); //格式化時間，顯示微秒數前兩位 echo strftime(&#039;%H:%M %S&#039;,$times[1]).substr($times[0], 1, 3);]]></description>
			<content:encoded><![CDATA[<p>要讓 PHP 時間顯示到微秒(百萬分之一秒)，可使用 microtime() 函式。此函式會傳回目前的UNIX時間戳記及微秒數(中間以一個空格隔開)。<br />
如：0.90625400 1106837367</p>
<pre title="code" class="php">

//將UNIX時間戳記和微秒數分別存入陣列
$times = split(&#039; &#039;, microtime());
//格式化時間，顯示微秒數前兩位
echo strftime(&#039;%H:%M %S&#039;,$times[1]).substr($times[0], 1, 3);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/21/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[PHP] 隱藏 IP 的寫法</title>
		<link>http://blog.linym.net/archives/14</link>
		<comments>http://blog.linym.net/archives/14#comments</comments>
		<pubDate>Sat, 18 Dec 2004 16:02:23 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[程式筆記]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://lym.fyman.idv.tw/blog/archives/14</guid>
		<description><![CDATA[經常我們為了保護客戶端的 IP 資訊，不會將完整 IP 顯示出來，變成像「210.240.xxx.xxx」這樣。在 PHP 上可用 explode() 這個函式來達到目的。explode() 可將字串依指定的字串或字元 separator 切開並存回一陣列。所以 IP 可依「.」切開，再分別顯示出來即可。 &#60;?php function ip_hide($ip, $n=0) { $iphide = explode(&#34;.&#34;, $ip); switch($n) { // 不隱藏IP case &#039;0&#039;: $ip; break; // 隱藏最末位 case &#039;1&#039;: $ip = $iphide[0].&#34;.&#34;.$iphide[1].&#34;.&#34;.$iphide[2].&#34;.X&#34;; break; // 隱藏末兩位 case &#039;2&#039;: $ip = $iphide[0].&#34;.&#34;.$iphide[1].&#34;.X.X&#34;; break; // 全部隱藏 case &#039;3&#039;: $ip = &#34;IP已經隱藏&#34;; break; [...]]]></description>
			<content:encoded><![CDATA[<p>經常我們為了保護客戶端的 IP 資訊，不會將完整 IP 顯示出來，變成像「210.240.xxx.xxx」這樣。在 PHP 上可用 explode() 這個函式來達到目的。explode() 可將字串依指定的字串或字元 separator 切開並存回一陣列。所以 IP 可依「.」切開，再分別顯示出來即可。</p>
<pre title="code" class="php">

&lt;?php
function ip_hide($ip, $n=0)
{
    $iphide = explode(&quot;.&quot;, $ip);
    switch($n) {
    // 不隱藏IP
    case &#039;0&#039;: $ip; break;
    // 隱藏最末位
    case &#039;1&#039;: $ip = $iphide[0].&quot;.&quot;.$iphide[1].&quot;.&quot;.$iphide[2].&quot;.X&quot;; break;
    // 隱藏末兩位
    case &#039;2&#039;: $ip = $iphide[0].&quot;.&quot;.$iphide[1].&quot;.X.X&quot;; break;
    // 全部隱藏
    case &#039;3&#039;: $ip = &quot;IP已經隱藏&quot;; break;
    }
    echo $ip;
}
?&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/14/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

