<?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>Life["Breathing"] &#187; php</title>
	<atom:link href="http://blog.hsin.tw/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.hsin.tw</link>
	<description></description>
	<lastBuildDate>Mon, 07 Jun 2010 07:30:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Zeus Request Rewriting : 301 redirect</title>
		<link>http://blog.hsin.tw/2010/zeus-request-rewriting-301-redirect/</link>
		<comments>http://blog.hsin.tw/2010/zeus-request-rewriting-301-redirect/#comments</comments>
		<pubDate>Thu, 03 Jun 2010 08:02:10 +0000</pubDate>
		<dc:creator>hsin</dc:creator>
				<category><![CDATA[server]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[redirect]]></category>
		<category><![CDATA[zeus]]></category>

		<guid isPermaLink="false">http://blog.hsin.tw/?p=401</guid>
		<description><![CDATA[這次的目標是把 http://myid.domainaaa.com 這個網址 轉到 http://www.domainbbb.com/myid 以下就是要寫在Request Rewriting裡的 RULE_0_START: match IN:Host into $ with ^([0-9a-zA-Z]{1,30})\.domainaaa\.com if not matched then goto RULE_0_END if matched set URL= http://www.domainbbb.com/$1 set RESPONSE = 301 set OUT:Location = %{URL} set BODY = &#60;a href=&#34;%{URL}&#34;&#62;go&#60;/a&#62; \n endif goto END RULE_0_END: [0-9a-zA-Z]{1,30}可以自己替換正規表示式的條件 這裡是挑出1~30個字的大小寫英文或數字 如果符合的話才會轉過去 參考資料： (好多XD) http://www.codingforums.com/showthread.php?t=156570 http://support.zeus.com/zws/examples/2006/03/07/rewrite_redirecting http://www.register365.com/knowledge/scripting/rewrite_scripts/528-zeus_rewrite_rules_user_guide.html http://www.chinazeus.com/read.php?tid=6 銅廠加印 同場加映 php [...]]]></description>
			<content:encoded><![CDATA[<p>這次的目標是把<br />
<span id="more-401"></span><br />
http://<span style="color:#000099;">myid</span><span style="color:#009900;">.domainaaa.com</span><br />
這個網址<br />
轉到<br />
http://www<span style="color:#990000;">.domainbbb.com</span>/<span style="color:#000099;">myid</span><br />
以下就是要寫在Request Rewriting裡的</p>
<pre class="brush: plain;">
RULE_0_START:
match IN:Host into $ with ^([0-9a-zA-Z]{1,30})\.domainaaa\.com
if not matched then goto RULE_0_END
if matched
	set URL= http://www.domainbbb.com/$1
	set RESPONSE = 301
	set OUT:Location = %{URL}
	set BODY = &lt;a href=&quot;%{URL}&quot;&gt;go&lt;/a&gt; \n
endif
goto END
RULE_0_END:
</pre>
<p>[0-9a-zA-Z]{1,30}可以自己替換正規表示式的條件<br />
這裡是挑出1~30個字的大小寫英文或數字<br />
如果符合的話才會轉過去</p>
<p>參考資料： (好多XD)<br />
<a href="http://www.codingforums.com/showthread.php?t=156570">http://www.codingforums.com/showthread.php?t=156570</a><br />
<a href="http://support.zeus.com/zws/examples/2006/03/07/rewrite_redirecting">http://support.zeus.com/zws/examples/2006/03/07/rewrite_redirecting</a><br />
<a href="http://www.register365.com/knowledge/scripting/rewrite_scripts/528-zeus_rewrite_rules_user_guide.html">http://www.register365.com/knowledge/scripting/rewrite_scripts/528-zeus_rewrite_rules_user_guide.html</a><br />
<a href="http://www.chinazeus.com/read.php?tid=6">http://www.chinazeus.com/read.php?tid=6</a></p>
<p><del datetime="2010-06-03T07:14:43+00:00">銅廠加印</del> 同場加映<br />
php header的301 redirect方法</p>
<pre class="brush: php;">
header(&quot;Location: http://www.domainbbb.com&quot;,TRUE,301);
exit;
</pre>
<p>怎麼php的簡潔很多XD</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hsin.tw/2010/zeus-request-rewriting-301-redirect/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>在IE中看iframe嵌入不同網域的網頁時 會無法使用cookie的問題</title>
		<link>http://blog.hsin.tw/2010/ie-blocking-iframe-cookie/</link>
		<comments>http://blog.hsin.tw/2010/ie-blocking-iframe-cookie/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 10:33:09 +0000</pubDate>
		<dc:creator>hsin</dc:creator>
				<category><![CDATA[瀏覽器]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.hsin.tw/?p=374</guid>
		<description><![CDATA[有些問題真的是不遇到就真的不知道會這樣阿~ 這幾天遇到這個問題 iframe如果嵌入了不同網域的網頁 則以IE看這網頁時 會無法使用cookie 應該是某些安全性的問題 但是只有IE會這樣就&#8230;&#8230;&#8230;&#8230;&#8230;&#124;&#124;&#124; 所幸經過咕狗大神的提點之後 在這裡找到了解決的辦法 IE Blocking iFrame Cookies 以php的解決方法來說 只要在每個會嵌入在iframe中的頁面裡加上這行 header('P3P:CP=&#34;IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT&#34;'); 就可以囉 其他還有 ASP.NET、Django、JSP的寫法就去原始頁面看囉]]></description>
			<content:encoded><![CDATA[<p>有些問題真的是不遇到就真的不知道會這樣阿~<br />
<span id="more-374"></span><br />
這幾天遇到這個問題<br />
iframe如果嵌入了不同網域的網頁<br />
則以IE看這網頁時 會無法使用cookie<br />
應該是某些安全性的問題<br />
但是只有IE會這樣就&#8230;&#8230;&#8230;&#8230;&#8230;|||</p>
<p>所幸經過咕狗大神的提點之後<br />
在這裡找到了解決的辦法<br />
<a href="http://adamyoung.net/IE-Blocking-iFrame-Cookies" target="_blank">IE Blocking iFrame Cookies</a></p>
<p>以php的解決方法來說<br />
只要在每個會嵌入在iframe中的頁面裡加上這行</p>
<pre class="brush: php;">
header('P3P:CP=&quot;IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT&quot;');
</pre>
<p>就可以囉</p>
<p>其他還有<br />
ASP.NET、Django、JSP的寫法就去原始頁面看囉</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hsin.tw/2010/ie-blocking-iframe-cookie/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>php 將數字補零 使用str_pad</title>
		<link>http://blog.hsin.tw/2009/php-pad-a-string/</link>
		<comments>http://blog.hsin.tw/2009/php-pad-a-string/#comments</comments>
		<pubDate>Mon, 11 May 2009 11:09:45 +0000</pubDate>
		<dc:creator>hsin</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.hsin.tw/?p=225</guid>
		<description><![CDATA[用php 補零去咕狗 會找到有些使用sprintf函式的方法 像下面這樣 $var = 1; echo sprintf(&#34;%02d&#34;, $var); 其實php本身就有一個專門可以補齊位數的函式 : str_pad() string str_pad ( string $input , int $pad_length [, string $pad_string= " " [, int $pad_type= STR_PAD_RIGHT ]] ) $input : 原字串 $pad_length : 補齊後的位數 $pad_string : 用來補齊的字串 $pad_type : 補齊的方式 有三種，STR_PAD_RIGHT (由右邊補)、STR_PAD_LEFT (由左邊補)、STR_PAD_BOTH (左右兩邊都補)， 預設為STR_PAD_RIGHT 所以其實不只可以補零，要補什麼字都可以 而以補零來舉例的話就是 $value = 7; //將數字由左邊補零至三位數 [...]]]></description>
			<content:encoded><![CDATA[<p>用<a href="http://www.google.com.tw/search?q=php+%E8%A3%9C%E9%9B%B6&#038;ie=utf-8&#038;oe=utf-8&#038;aq=t&#038;rls=org.mozilla:zh-TW:official&#038;client=firefox-a" target="_blank">php 補零</a>去咕狗<br />
<span id="more-225"></span><br />
會找到有些使用sprintf函式的方法 像下面這樣</p>
<pre class="brush: php;">
$var = 1;
echo sprintf(&quot;%02d&quot;, $var);
</pre>
<p>其實php本身就有一個專門可以補齊位數的函式 : <a href="http://tw2.php.net/str_pad" target="_blank">str_pad()</a></p>
<p>string str_pad  ( string $input  , int $pad_length  [, string $pad_string= " "  [, int $pad_type= STR_PAD_RIGHT  ]] )</p>
<p>$input : 原字串<br />
$pad_length : 補齊後的位數<br />
$pad_string : 用來補齊的字串<br />
$pad_type : 補齊的方式 有三種，STR_PAD_RIGHT (由右邊補)、STR_PAD_LEFT (由左邊補)、STR_PAD_BOTH (左右兩邊都補)， 預設為STR_PAD_RIGHT</p>
<p>所以其實不只可以補零，要補什麼字都可以<br />
而以補零來舉例的話就是</p>
<pre class="brush: php;">
$value = 7;
//將數字由左邊補零至三位數
$value = str_pad($value,3,'0',STR_PAD_LEFT);
echo $value;
// 結果會印出 007;

//下面這是document裡的例子
$input = &quot;Alien&quot;;
echo str_pad($input, 10);                      // produces &quot;Alien     &quot;
echo str_pad($input, 10, &quot;-=&quot;, STR_PAD_LEFT);  // produces &quot;-=-=-Alien&quot;
echo str_pad($input, 10, &quot;_&quot;, STR_PAD_BOTH);   // produces &quot;__Alien___&quot;
echo str_pad($input, 6 , &quot;___&quot;);               // produces &quot;Alien_&quot;
</pre>
<p>這樣應該就可以瞭解這個函式的用法了~</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hsin.tw/2009/php-pad-a-string/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>php 設定跨子網域的SESSION</title>
		<link>http://blog.hsin.tw/2009/php-pass-session-data-between-subdomains/</link>
		<comments>http://blog.hsin.tw/2009/php-pass-session-data-between-subdomains/#comments</comments>
		<pubDate>Thu, 23 Apr 2009 02:09:33 +0000</pubDate>
		<dc:creator>hsin</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.hsin.tw/?p=218</guid>
		<description><![CDATA[要在php中設定可以跨子網域使用同樣的SESSION 可以在php.ini中多加一行 session.cookie_domain = .mydomain.com 要記得網域前的 . 喔 如果不能修改php.ini的話 就在每個要跨子網域的程式中加入下面這行 ini_set(&#34;session.cookie_domain&#34;, &#34;.mydomain.com&#34;); 都要在session_start()之前喔 同樣的 網域前的 . 也是不能省的~ 這只能使用在不同子網域的同網域中喔 就是AAA.mydomain.com跟BBB.mydomain.com可以通 AA.mydomain.com跟BB.yourdomain.com不能通 因為是不同網域 參考資訊：Pass Sessions between subdomains in php]]></description>
			<content:encoded><![CDATA[<p>要在php中設定可以跨子網域使用同樣的SESSION<br />
<span id="more-218"></span><br />
可以在php.ini中多加一行</p>
<pre class="brush: plain;">

session.cookie_domain = .mydomain.com
</pre>
<p>要記得網域前的 <strong>.</strong> 喔</p>
<p>如果不能修改php.ini的話<br />
就在每個要跨子網域的程式中加入下面這行</p>
<pre class="brush: php;">

ini_set(&quot;session.cookie_domain&quot;, &quot;.mydomain.com&quot;);
</pre>
<p>都要在session_start()之前喔<br />
同樣的 網域前的 <strong>.</strong> 也是不能省的~</p>
<p>這只能使用在不同子網域的同網域中喔<br />
就是AAA<span style="color:#0000cc;">.mydomain.com</span>跟BBB<span style="color:#0000cc;">.mydomain.com</span>可以通<br />
AA<span style="color:#0000cc;">.mydomain.com</span>跟BB<span style="color:#cc0000;">.yourdomain.com</span>不能通 因為是不同網域</p>
<p>參考資訊：<a target="_blank" href="http://www.madcarrot.co.uk/2005/08/pass_sessions_b.html">Pass Sessions between subdomains in php</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hsin.tw/2009/php-pass-session-data-between-subdomains/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>rss note</title>
		<link>http://blog.hsin.tw/2009/rss-note/</link>
		<comments>http://blog.hsin.tw/2009/rss-note/#comments</comments>
		<pubDate>Thu, 05 Mar 2009 06:08:04 +0000</pubDate>
		<dc:creator>hsin</dc:creator>
				<category><![CDATA[rss]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[瀏覽器]]></category>

		<guid isPermaLink="false">http://blog.hsin.tw/?p=160</guid>
		<description><![CDATA[一些關於rss的東西 RSS 2.0 Specification( RSS2.0规范 、 RSS2.0技术规范摘录 ) PHP 產生 RSS/ATOM pubDate/created 所需格式 PHP Universal Feed Generator (supports RSS 1.0, RSS 2.0 and ATOM) 讓瀏覽器偵測到rss feed 要在&#60;head&#62;&#60;/head&#62;裡面加上這行 &#60;link rel="alternate" type="application/rss+xml" title="標題" href="rss路徑" /&#62; 可以有不只一個feed 有幾個寫幾行 CDATA 區段 [XML 標準] 加上&#60;![CDATA[ 內容 ]]&#62; 這段的不會被XML解析 在PHP的date()函數中可使用date("r")來表示rss規範中的時間 rss規範裡的日期是依照RFC 822的格式 而date("r")是依照RFC 2822 兩者對於時間的差異是在年份 前者是顯示兩位數 後者是顯示四位數 所以可以直接使用date("r")]]></description>
			<content:encoded><![CDATA[<p>一些關於rss的東西<br />
<span id="more-160"></span><br />
<a href="http://www.rssboard.org/rss-specification" target="_blank">RSS 2.0 Specification</a>( <a href="http://www.irsser.com/article.asp?id=33" target="_blank">RSS2.0规范</a> 、 <a href="http://www.cnbruce.com/blog/showlog.asp?log_id=949&amp;cat_id=34" target="_blank">RSS2.0技术规范摘录</a> )<br />
<a href="http://plog.longwin.com.tw/programming/2008/04/24/php_rss_atom_date_format_generator_2008" target="_blank">PHP 產生 RSS/ATOM pubDate/created 所需格式</a><br />
<a href="http://www.ajaxray.com/blog/2008/03/08/php-universal-feed-generator-supports-rss-10-rss-20-and-atom/" target="_blank">PHP Universal Feed Generator (supports RSS 1.0, RSS 2.0 and ATOM)</a></p>
<p>讓瀏覽器偵測到rss feed<br />
要在&lt;head&gt;&lt;/head&gt;裡面加上這行<br />
&lt;link rel="alternate" type="application/rss+xml" title="標題" href="rss路徑" /&gt;<br />
可以有不只一個feed<br />
有幾個寫幾行</p>
<p><a href="http://msdn.microsoft.com/zh-tw/library/ms256076(VS.80).aspx" target="_blank">CDATA 區段 [XML 標準]</a><br />
加上&lt;![CDATA[ 內容 ]]&gt; 這段的不會被XML解析</p>
<p>在<a href="http://www.php.net/date" target="_blank">PHP的date()函數</a>中可使用date("r")來表示rss規範中的時間<br />
rss規範裡的日期是依照<a href="http://asg.web.cmu.edu/rfc/rfc822.html" target="_blank">RFC 822</a>的格式<br />
而date("r")是依照<a class="link external" href="http://www.faqs.org/rfcs/rfc2822" target="_blank">RFC 2822</a><br />
兩者對於時間的差異是在年份<br />
前者是顯示兩位數 後者是顯示四位數<br />
所以可以直接使用date("r")</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hsin.tw/2009/rss-note/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>php 傳送get到別的URL並取得回應內容 使用fsockopen</title>
		<link>http://blog.hsin.tw/2009/php-get-method-fsockopen/</link>
		<comments>http://blog.hsin.tw/2009/php-get-method-fsockopen/#comments</comments>
		<pubDate>Wed, 25 Feb 2009 11:42:04 +0000</pubDate>
		<dc:creator>hsin</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.hsin.tw/?p=140</guid>
		<description><![CDATA[在這篇有提到傳送post的用法 另外說到如果只是要傳送get就可以直接使用fopen或是file_get_contents函式直接取得網頁內容 BUT！！！ 這兩天遇到了一個問題 如果因為安全性的關係 要把php.ini中的allow_url_fopen關起來(也就是off) 那就不能使用前述的函式來取得網頁內容 所以只好找另外的方法 也就是使用fsockopen模擬傳送~ (鏘鏘鏘～) 以下是php部份 function SendGET($_url){ $url = parse_url($_url); $contents = ''; $url_port = $url['port']==''?80:$url['port']; $fp = fsockopen($url['host'],$url_port); if($fp){ $_request = $url['path'].($url['query']==''?'':'?'.$url['query']).($url['fragment']==''?'':'#'.$url['fragment']); fputs($fp,'GET '.(($_request=='')?'/':$_request).&#34; HTTP/1.0\r\n&#34;); fputs($fp,&#34;Host: &#34;.$url['host'].&#34;\n&#34;); fputs($fp,&#34;Content-type: application/x-www-form-urlencoded\n&#34;); fputs($fp,&#34;Connection: close\n\n&#34;); $line = fgets($fp,1024); if(!eregi(&#34;^HTTP/1\.. 200&#34;, $line)) return; else{ $results = ''; $contents = ''; $inheader = 1; [...]]]></description>
			<content:encoded><![CDATA[<p>在<a target="_blank" href="http://blog.hsin.tw/2009/php-post-method-fsockopen/">這篇</a>有提到傳送post的用法<br />
<span id="more-140"></span><br />
另外說到如果只是要傳送get就可以直接使用fopen或是file_get_contents函式直接取得網頁內容<br />
BUT！！！<br />
這兩天遇到了一個問題<br />
如果因為安全性的關係<br />
要把php.ini中的allow_url_fopen關起來(也就是off)<br />
那就不能使用前述的函式來取得網頁內容<br />
所以只好找另外的方法<br />
也就是使用fsockopen模擬傳送~<br />
(鏘鏘鏘～)</p>
<p>以下是php部份</p>
<pre class="brush: php;">
function SendGET($_url){
  $url = parse_url($_url);
  $contents = '';
  $url_port = $url['port']==''?80:$url['port'];
  $fp = fsockopen($url['host'],$url_port);
  if($fp){
    $_request = $url['path'].($url['query']==''?'':'?'.$url['query']).($url['fragment']==''?'':'#'.$url['fragment']);
    fputs($fp,'GET '.(($_request=='')?'/':$_request).&quot; HTTP/1.0\r\n&quot;);
    fputs($fp,&quot;Host: &quot;.$url['host'].&quot;\n&quot;);
    fputs($fp,&quot;Content-type: application/x-www-form-urlencoded\n&quot;);
    fputs($fp,&quot;Connection: close\n\n&quot;);
    $line = fgets($fp,1024);
    if(!eregi(&quot;^HTTP/1\.. 200&quot;, $line)) return;
    else{
      $results = '';
      $contents = '';
      $inheader = 1;
      while(!feof($fp)){
        $line = fgets($fp,2048);
        if($inheader&amp;&amp;($line == &quot;\n&quot; || $line == &quot;\r\n&quot;)){
          $inheader = 0;
        }elseif(!$inheader){
          $contents .= $line;
        }
      }
      fclose($fp);
    }
  }
  return $contents;
}
</pre>
<pre class="brush: php;">
//使用方式很簡單
$url = 'http://someone.com:80/index.php?mode=go&amp;id=hsin#top';
//把網址填入參數即可
$_result = SendGET($url);
//回傳的值就是內容
print_r($_result);
</pre>
<p>參考資訊：<a target="_blank" href="http://www.maorr.com/read.php/447.htm">http://www.maorr.com/read.php/447.htm</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hsin.tw/2009/php-get-method-fsockopen/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>php 傳送POST到別的URL並取得回應內容 使用fsockopen</title>
		<link>http://blog.hsin.tw/2009/php-post-method-fsockopen/</link>
		<comments>http://blog.hsin.tw/2009/php-post-method-fsockopen/#comments</comments>
		<pubDate>Sat, 17 Jan 2009 08:52:52 +0000</pubDate>
		<dc:creator>hsin</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.hsin.tw/?p=109</guid>
		<description><![CDATA[如果不需要傳送參數或是使用GET method傳送 可以直接使用fopen()或是file_get_contents()函式獲得回應內容 但是如果需要不經過表單就送出POST給某URL 就需要使用curl相關函式或是fsockopen()傳送 curl的用法比較簡單 可以咕狗看看(但是php必須要先安裝curl才可以用) 這邊要講的是fsockopen() //接收POST參數的URL $url = 'http://www.google.com'; //POST參數,在這個陣列裡,索引是name,值是value,沒有限定組數 $postdata = array('post_name'=&#62;'post_value','acc'=&#62;'hsin','nick'=&#62;'joe'); //函式回覆的值就是取得的內容 $result = sendpost($url,$postdata); function sendpost($url, $data){ //先解析url 取得的資訊可以看看http://www.php.net/parse_url $url = parse_url($url); $url_port = $url['port']==''?(($url['scheme']=='https')?443:80):$url['port']; if(!$url) return &#34;couldn't parse url&#34;; //對要傳送的POST參數作處理 $encoded = &#34;&#34;; while(list($k,$v)=each($data)){ $encoded .= ($encoded?'&#38;':''); $encoded .= rawurlencode($k).&#34;=&#34;.rawurlencode($v); } //開啟一個socket $fp = fsockopen($url['host'],$url_port); if(!$fp) return &#34;Failed [...]]]></description>
			<content:encoded><![CDATA[<p>如果不需要傳送參數或是使用GET method傳送<br />
<span id="more-109"></span><br />
可以直接使用fopen()或是file_get_contents()函式獲得回應內容<br />
但是如果需要不經過表單就送出POST給某URL<br />
就需要使用curl相關函式或是fsockopen()傳送<br />
curl的用法比較簡單<br />
可以咕狗看看(但是php必須要先安裝curl才可以用)<br />
這邊要講的是fsockopen()</p>
<pre class="brush: php;">
//接收POST參數的URL
$url = 'http://www.google.com';
//POST參數,在這個陣列裡,索引是name,值是value,沒有限定組數
$postdata = array('post_name'=&gt;'post_value','acc'=&gt;'hsin','nick'=&gt;'joe');
//函式回覆的值就是取得的內容
$result = sendpost($url,$postdata);

function sendpost($url, $data){
//先解析url 取得的資訊可以看看http://www.php.net/parse_url
$url = parse_url($url);
$url_port = $url['port']==''?(($url['scheme']=='https')?443:80):$url['port'];
if(!$url) return &quot;couldn't parse url&quot;;
//對要傳送的POST參數作處理
$encoded = &quot;&quot;;
while(list($k,$v)=each($data)){
  $encoded .= ($encoded?'&amp;':'');
  $encoded .= rawurlencode($k).&quot;=&quot;.rawurlencode($v);
}
//開啟一個socket
$fp = fsockopen($url['host'],$url_port);
if(!$fp) return &quot;Failed to open socket to &quot;.$url['host'];
//header的資訊
fputs($fp,'POST '.$url['path'].($url['query']?'?'.$url['query']:'').&quot; HTTP/1.0rn&quot;);
fputs($fp,&quot;Host: &quot;.$url['host'].&quot;n&quot;);
fputs($fp,&quot;Content-type: application/x-www-form-urlencodedn&quot;);
fputs($fp,&quot;Content-length: &quot;.strlen($encoded).&quot;n&quot;);
fputs($fp,&quot;Connection: closenn&quot;);
fputs($fp,$encoded.&quot;n&quot;);
//取得回應的內容
$line = fgets($fp,1024);
if(!eregi(&quot;^HTTP/1.. 200&quot;, $line)) return;
$results = &quot;&quot;;
$inheader = 1;
while(!feof($fp)){
  $line = fgets($fp,2048);
  if($inheader&amp;&amp;($line == &quot;n&quot; || $line == &quot;rn&quot;)){
    $inheader = 0;
  }elseif(!$inheader){
    $results .= $line;
  }
}
fclose($fp);
return $results;
}
</pre>
<p>參考資訊：<a href="http://www.phpe.net/faq/71.shtml" target="_blank">http://www.phpe.net/faq/71.shtml</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hsin.tw/2009/php-post-method-fsockopen/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>php 解析xml</title>
		<link>http://blog.hsin.tw/2008/php-parse-xml/</link>
		<comments>http://blog.hsin.tw/2008/php-parse-xml/#comments</comments>
		<pubDate>Mon, 29 Dec 2008 15:52:18 +0000</pubDate>
		<dc:creator>hsin</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://blog.hsin.tw/?p=101</guid>
		<description><![CDATA[php本身就有函數可以處理xml 這邊以本站的rss feed作例子 //取得xml檔 $xml_file='http://blog.hsin.tw/feed/'; //必須使用fopen開啟 不能直接用喔 $fp = fopen($xml_file,'r'); //這是php官網介紹使用外部連結時的fread方法 $contents = ''; while (!feof($fp)) { $contents .= fread($fp, 8192); } //首先建立一個解析器，編碼不是必要的，這邊設定utf-8 $xp = xml_parser_create('utf-8'); //建立起始和終止元素處理器 下面函式的地方會講 xml_set_element_handler($xp,&#34;startElement&#34;,&#34;endElement&#34;); //建立資料處理器 下面函式的地方會講 xml_set_character_data_handler($xp,&#34;characterData&#34;); //開始解析xml檔 $result = xml_parse($xp,$contents); //我是處理成以標籤為索引、內容為值的陣列，以print_r印出來看結果 print_r($_request); //起始元素處理器 //當遇到xml檔裡面的每個標籤&#60;tag&#62;時，就會開始呼叫這個函式處理 //我這裡是把每個標籤名稱都換成小寫，待會給資料處理器使用 function startElement($parser,$tag,$atts) { global $_i,$_x,$_request; $_x = strtolower($tag); if($_x=='item') ++$_i; } //終止元素處理器 //當遇到xml檔裡面的每個標籤&#60;/tag&#62;結束時，就會開始呼叫這個函式處理 //我這裡沒有作任何處理 [...]]]></description>
			<content:encoded><![CDATA[<p>php本身就有函數可以處理xml<br />
<span id="more-101"></span><br />
這邊以本站的rss feed作例子</p>
<pre class="brush: php;">
//取得xml檔
$xml_file='http://blog.hsin.tw/feed/';
//必須使用fopen開啟 不能直接用喔
$fp = fopen($xml_file,'r');
//這是php官網介紹使用外部連結時的fread方法
$contents = '';
while (!feof($fp)) {
  $contents .= fread($fp, 8192);
}
//首先建立一個解析器，編碼不是必要的，這邊設定utf-8
$xp = xml_parser_create('utf-8');
//建立起始和終止元素處理器 下面函式的地方會講
xml_set_element_handler($xp,&quot;startElement&quot;,&quot;endElement&quot;);
//建立資料處理器 下面函式的地方會講
xml_set_character_data_handler($xp,&quot;characterData&quot;);
//開始解析xml檔
$result = xml_parse($xp,$contents);
//我是處理成以標籤為索引、內容為值的陣列，以print_r印出來看結果
print_r($_request);
//起始元素處理器
//當遇到xml檔裡面的每個標籤&lt;tag&gt;時，就會開始呼叫這個函式處理
//我這裡是把每個標籤名稱都換成小寫，待會給資料處理器使用
function startElement($parser,$tag,$atts)
{
	global $_i,$_x,$_request;
	$_x = strtolower($tag);
  if($_x=='item')
    ++$_i;
}
//終止元素處理器
//當遇到xml檔裡面的每個標籤&lt;/tag&gt;結束時，就會開始呼叫這個函式處理
//我這裡沒有作任何處理
function endElement($parser,$tag)
{}
//資料處理器
//會對每個標籤中的內容作處理
//這裡是把標籤名稱設為索引、內容設為值
function characterData($parser,$d)
{
	global $_i,$_x,$_request;
	if(trim($d)!='')
	{
  	$_request[$_i][$_x]=$d;
  }
}
</pre>
<p>startElement、endElement、characterData<br />
三個函式的名稱都可以自己訂喔<br />
不是固定的</p>
<p><a href="http://ex.hsin.tw/index.php?type=php&#038;act=p01" target="_blank">按這裡可以看範例</a></p>
<p>相關連結：<a href="http://www.zishu.cn/blogview.asp?logID=383" target="_blank">用PHP解析XML</a></p>
<p>update:<br />
使用php5以上的朋友可以試試這兩個函式<a href="http://tw.php.net/simplexml_load_string" target="_blank">simplexml_load_string</a> <a href="http://tw.php.net/simplexml_load_file" target="_blank">simplexml_load_file</a>喔，方便很多～</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hsin.tw/2008/php-parse-xml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>php 解壓縮zip 使用pclzip</title>
		<link>http://blog.hsin.tw/2008/php-pclzip/</link>
		<comments>http://blog.hsin.tw/2008/php-pclzip/#comments</comments>
		<pubDate>Sun, 21 Dec 2008 12:04:42 +0000</pubDate>
		<dc:creator>hsin</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[zip]]></category>

		<guid isPermaLink="false">http://blog.hsin.tw/?p=28</guid>
		<description><![CDATA[前幾天為了要讓人上傳壓縮檔所以咕狗了一下 然後就找到了這個pclZip，是一個class，所以很好使用，include檔案就可以用了。 其實他也可以壓縮檔案，只是我還用不到，所以下面講的都比較有關解壓縮。 這是最基本的用法： require_once('pclzip.lib.php'); $archive = new PclZip('archive.zip'); $archive-&#62;extract(); 這樣就可以把archive.zip這個檔案解壓縮到當前目錄！傷當的簡單阿！ 不過記得解壓縮到的目錄的權限要可以寫入，不然會卡住，我因為這個卡很久阿&#8230;很笨=..= 他每個method還可以加上許多的參數，可以讓壓縮檔更帥&#8230;(什麼鬼) 下面是我把官網上有寫的參數都翻一下，細節可以自己到這裡研究看看 參數 引數 說明 PCLZIP_OPT_PATH 字串 要解壓縮到哪的路徑。可用於extract()、extractByIndex()。 PCLZIP_OPT_ADD_PATH 字串 增加一個目錄。可用於create()、add()、extract()。(使用於create()時，是把要壓縮的檔案放進這個目錄中再壓縮，使用於extract()時，是在要解壓縮的路徑中增加此目錄，並解壓縮到此目錄中)。 PCLZIP_OPT_REMOVE_PATH 字串 移除部份的目錄路徑，例如原本檔案所在的目錄為aa/bb/cc/test.test.txt，但是希望壓縮或解壓縮後的路徑為cc/test.txt，就可以使用PCLZIP_OPT_REMOVE_PATH,"aa/bb"。可用於create()、add()、extract()、extractByIndex()。(與PCLZIP_OPT_REMOVE_ALL_PATH一起用的時候會被自動忽略) PCLZIP_OPT_REMOVE_ALL_PATH &#8211; 移除所有檔案的目錄，所有檔案都會被解壓縮或壓縮到當前或是指定的目錄中，請注意如果有不同目錄的相同名稱檔案，使用此參數時會被覆蓋，此參數不需要引數。可用於create()、add()、extract()、extractByIndex()。 PCLZIP_OPT_SET_CHMOD CHMOD值 設定解壓縮出來的檔案的CHMOD值。可用於extract()、extractByIndex()。 PCLZIP_OPT_BY_NAME 檔案名稱 僅解壓縮引數中所指定的檔案，檔案名稱可以用陣列或是逗號隔開表示。 PCLZIP_OPT_BY_EREG RegEx字串 僅解壓縮引數中正規表達式比對檔名正確的檔案，使用php中的ereg()函式比對。 PCLZIP_OPT_BY_PREG RegEx字串 僅解壓縮引數中正規表達式比對檔名正確的檔案，使用php中的preg_match()函式比對。 PCLZIP_OPT_BY_INDEX 陣列 僅解壓縮引數陣列中各元素所指定順序的檔案。(這個我還不太懂是照什麼順序，似乎不是照字母排) PCLZIP_OPT_EXTRACT_AS_STRING &#8211; 將一個檔案的內容解壓縮成一個字串，通常可能用於只需要看readme檔案的情況。請注意如果一次解壓縮太多檔案，有可能會將記憶體耗盡。 PCLZIP_OPT_EXTRACT_IN_OUTPUT &#8211; 將一個檔案的內容解壓縮並直接輸出(即類似直接echo此結果)。 PCLZIP_OPT_NO_COMPRESSION &#8211; 將一個檔案加入此壓縮檔內，此檔案不會被壓縮，僅是放入同一個壓縮檔中。 PCLZIP_OPT_COMMENT 字串 [...]]]></description>
			<content:encoded><![CDATA[<p>前幾天為了要讓人上傳壓縮檔所以咕狗了一下<br />
<span id="more-28"></span><br />
然後就找到了這個<a href="http://www.phpconcept.net/pclzip/man/en/index.php" target="_blank">pclZip</a>，是一個class，所以很好使用，include檔案就可以用了。<br />
其實他也可以壓縮檔案，只是我還用不到，所以下面講的都比較有關解壓縮。</p>
<p>這是最基本的用法：</p>
<pre class="brush: php;">
  require_once('pclzip.lib.php');
  $archive = new PclZip('archive.zip');
  $archive-&gt;extract();
</pre>
<p>
這樣就可以把archive.zip這個檔案解壓縮到當前目錄！傷當的簡單阿！<br />
不過記得解壓縮到的目錄的權限要可以寫入，不然會卡住，我因為這個卡很久阿&#8230;很笨=..=</p>
<p>他每個method還可以加上許多的參數，可以讓壓縮檔更帥&#8230;(什麼鬼)<br />
下面是我把官網上有寫的參數都翻一下，<a href="http://www.phpconcept.net/pclzip/man/en/index.php?options" target="_blank">細節可以自己到這裡研究看看</a></p>
<table style="font-size:12px;" width="550" border=1 cellspacing=1 cellpadding=3 bgcolor="#6e6e6e">
<tr bgcolor="#dedede">
<th width="200">參數</th>
<th width="200">引數</th>
</tr>
<tr bgcolor="#dedede">
<th width="400" colspan="2">說明</th>
</tr>
<tr bgcolor="#ffffff">
<td>PCLZIP_OPT_PATH</td>
<td>字串</td>
</tr>
<tr bgcolor="#ffffff">
<td colspan="2">
      要解壓縮到哪的路徑。可用於extract()、extractByIndex()。
    </td>
</tr>
<tr bgcolor="#dedede">
<th colspan="2"></th>
</tr>
<tr bgcolor="#ffffff">
<td>PCLZIP_OPT_ADD_PATH</td>
<td>字串</td>
</tr>
<tr bgcolor="#ffffff">
<td colspan="2">
      增加一個目錄。可用於create()、add()、extract()。(使用於create()時，是把要壓縮的檔案放進這個目錄中再壓縮，使用於extract()時，是在要解壓縮的路徑中增加此目錄，並解壓縮到此目錄中)。
    </td>
</tr>
<tr bgcolor="#dedede">
<th colspan="2"></th>
</tr>
<tr bgcolor="#ffffff">
<td>PCLZIP_OPT_REMOVE_PATH</td>
<td>字串</td>
</tr>
<tr bgcolor="#ffffff">
<td colspan="2">
移除部份的目錄路徑，例如原本檔案所在的目錄為aa/bb/cc/test.test.txt，但是希望壓縮或解壓縮後的路徑為cc/test.txt，就可以使用PCLZIP_OPT_REMOVE_PATH,"aa/bb"。可用於create()、add()、extract()、extractByIndex()。(與PCLZIP_OPT_REMOVE_ALL_PATH一起用的時候會被自動忽略)
    </td>
</tr>
<tr bgcolor="#dedede">
<th colspan="2"></th>
</tr>
<tr bgcolor="#ffffff">
<td>PCLZIP_OPT_REMOVE_ALL_PATH</td>
<td>&#8211;</td>
</tr>
<tr bgcolor="#ffffff">
<td colspan="2">
移除所有檔案的目錄，所有檔案都會被解壓縮或壓縮到當前或是指定的目錄中，請注意如果有不同目錄的相同名稱檔案，使用此參數時會被覆蓋，此參數不需要引數。可用於create()、add()、extract()、extractByIndex()。
    </td>
</tr>
<tr bgcolor="#dedede">
<th colspan="2"></th>
</tr>
<tr bgcolor="#ffffff">
<td>PCLZIP_OPT_SET_CHMOD</td>
<td>CHMOD值</td>
</tr>
<tr bgcolor="#ffffff">
<td colspan="2">
設定解壓縮出來的檔案的CHMOD值。可用於extract()、extractByIndex()。
    </td>
</tr>
<tr bgcolor="#dedede">
<th colspan="2"></th>
</tr>
<tr bgcolor="#ffffff">
<td>PCLZIP_OPT_BY_NAME</td>
<td>檔案名稱</td>
</tr>
<tr bgcolor="#ffffff">
<td colspan="2">
僅解壓縮引數中所指定的檔案，檔案名稱可以用陣列或是逗號隔開表示。
    </td>
</tr>
<tr bgcolor="#dedede">
<th colspan="2"></th>
</tr>
<tr bgcolor="#ffffff">
<td>PCLZIP_OPT_BY_EREG</td>
<td>RegEx字串</td>
</tr>
<tr bgcolor="#ffffff">
<td colspan="2">
僅解壓縮引數中正規表達式比對檔名正確的檔案，使用php中的ereg()函式比對。
    </td>
</tr>
<tr bgcolor="#dedede">
<th colspan="2"></th>
</tr>
<tr bgcolor="#ffffff">
<td>PCLZIP_OPT_BY_PREG</td>
<td>RegEx字串</td>
</tr>
<tr bgcolor="#ffffff">
<td colspan="2">
僅解壓縮引數中正規表達式比對檔名正確的檔案，使用php中的preg_match()函式比對。
    </td>
</tr>
<tr bgcolor="#dedede">
<th colspan="2"></th>
</tr>
<tr bgcolor="#ffffff">
<td>PCLZIP_OPT_BY_INDEX</td>
<td>陣列</td>
</tr>
<tr bgcolor="#ffffff">
<td colspan="2">
僅解壓縮引數陣列中各元素所指定順序的檔案。(這個我還不太懂是照什麼順序，似乎不是照字母排)
    </td>
</tr>
<tr bgcolor="#dedede">
<th colspan="2"></th>
</tr>
<tr bgcolor="#ffffff">
<td>PCLZIP_OPT_EXTRACT_AS_STRING</td>
<td>&#8211;</td>
</tr>
<tr bgcolor="#ffffff">
<td colspan="2">
將一個檔案的內容解壓縮成一個字串，通常可能用於只需要看readme檔案的情況。請注意如果一次解壓縮太多檔案，有可能會將記憶體耗盡。
    </td>
</tr>
<tr bgcolor="#dedede">
<th colspan="2"></th>
</tr>
<tr bgcolor="#ffffff">
<td>PCLZIP_OPT_EXTRACT_IN_OUTPUT</td>
<td>&#8211;</td>
</tr>
<tr bgcolor="#ffffff">
<td colspan="2">
將一個檔案的內容解壓縮並直接輸出(即類似直接echo此結果)。
    </td>
</tr>
<tr bgcolor="#dedede">
<th colspan="2"></th>
</tr>
<tr bgcolor="#ffffff">
<td>PCLZIP_OPT_NO_COMPRESSION</td>
<td>&#8211;</td>
</tr>
<tr bgcolor="#ffffff">
<td colspan="2">
將一個檔案加入此壓縮檔內，此檔案不會被壓縮，僅是放入同一個壓縮檔中。
    </td>
</tr>
<tr bgcolor="#dedede">
<th colspan="2"></th>
</tr>
<tr bgcolor="#ffffff">
<td>PCLZIP_OPT_COMMENT</td>
<td>字串</td>
</tr>
<tr bgcolor="#ffffff">
<td colspan="2">
建立壓縮檔時增加一個註解，如果原本已經有註解的話，將會直接覆蓋過去。
    </td>
</tr>
<tr bgcolor="#dedede">
<th colspan="2"></th>
</tr>
<tr bgcolor="#ffffff">
<td>PCLZIP_OPT_ADD_COMMENT</td>
<td>字串</td>
</tr>
<tr bgcolor="#ffffff">
<td colspan="2">
建立壓縮檔時增加一個註解，如果原本已經有註解的話，將會接在後面。
    </td>
</tr>
<tr bgcolor="#dedede">
<th colspan="2"></th>
</tr>
<tr bgcolor="#ffffff">
<td>PCLZIP_OPT_PREPEND_COMMENT</td>
<td>字串</td>
</tr>
<tr bgcolor="#ffffff">
<td colspan="2">
建立壓縮檔時增加一個註解，如果原本已經有註解的話，將會把原先的註解接在此字串的後面。
    </td>
</tr>
</table>
<p>
下面這些是範例，其實就跟官網的user manual內容一樣：</p>
<pre class="brush: php;">
//解壓縮到extract/folder/這個目錄中
$list = $archive-&gt;extract(PCLZIP_OPT_PATH, &quot;extract/folder/&quot;);

//增加這個目錄在壓縮檔中，完成以後壓縮檔裡面會有backup這個目錄，backup裡面會有這兩個檔案
$list = $archive-&gt;create(&quot;file.txt,image.gif&quot;,PCLZIP_OPT_ADD_PATH, &quot;backup&quot;);

//去掉部份的路徑，這裡完成後會變成test/file.txt
$list = $archive-&gt;add(&quot;/usr/local/user/test/file.txt&quot;,PCLZIP_OPT_REMOVE_PATH, &quot;/usr/local/user&quot;);

//把所有路徑都去掉，這個壓縮檔建立完後，裡面就只會有file.txt跟image.gif，不會有目錄了
$list = $archive-&gt;create(&quot;data/file.txt images/image.gif&quot;,PCLZIP_OPT_REMOVE_ALL_PATH);

//把解壓縮出來的檔案的CHMOD設成0777
$list = $archive-&gt;extract(PCLZIP_OPT_SET_CHMOD, 0777);

//解壓縮部份的檔案，這個參數是使用檔案名稱判別
//引數可以用下面這樣的陣列
$rule_list[0] = 'test/aaa.txt';
$rule_list[1] = 'test/ddd.txt';
//或是下面這樣，一個字串中，用逗號分隔每個要解壓縮的檔案
$rule_list = &quot;test/aaa.txt,test/ddd.txt&quot;;
$list = $archive-&gt;extract(PCLZIP_OPT_BY_NAME,$rule_list);

//解壓縮部份的檔案，使用php的ereg()函式，檔案名稱有比對成功的都會被解壓縮
$list = $archive-&gt;extract(PCLZIP_OPT_BY_EREG, &quot;aa&quot;);

//解壓縮部份的檔案，使用php的preg_match()函式，檔案名稱有比對成功的都會被解壓縮
$list = $archive-&gt;extract(PCLZIP_OPT_BY_PREG, &quot;/^bb/&quot;);
//上面這兩個函式如果不懂的話，請先研究正規表示法(Regular Expression)

//依照陣列中元素的索引解壓縮，可是我不太懂index啥 = =a
$list = $archive-&gt;extract(PCLZIP_OPT_BY_INDEX, array('0-1','6-7'));

//將一個檔案內容解壓縮成一個字串
$list = $archive-&gt;extract(PCLZIP_OPT_BY_NAME, &quot;data/readme.txt&quot;,PCLZIP_OPT_EXTRACT_AS_STRING);

//將一個檔案內容解壓縮完後直接輸出(echo)
$list = $archive-&gt;extract(PCLZIP_OPT_BY_NAME, &quot;data/readme.txt&quot;,PCLZIP_OPT_EXTRACT_IN_OUTPUT);

//將一個檔案加入一個壓縮檔中，但不會對此檔案壓縮
$list = $archive-&gt;add(&quot;data/file.txt&quot;, PCLZIP_OPT_NO_COMPRESSION);

//對此壓縮檔增加一個註解，如果原本就有註解的話會被覆蓋掉
$list = $archive-&gt;create(&quot;data&quot;, PCLZIP_OPT_COMMENT, &quot;Add a comment&quot;);

//對此壓縮檔增加一個註解，如果原本就有註解的話會接在後面
$list = $archive-&gt;add(&quot;data&quot;, PCLZIP_OPT_ADD_COMMENT, &quot;Add a comment after the existing one&quot;);

//對此壓縮檔增加一個註解，如果原本就有註解的話會放在原本的註解前面
$list = $archive-&gt;add(&quot;data&quot;, PCLZIP_OPT_PREPEND_COMMENT, &quot;Add a comment before the existing one&quot;);
</pre>
<p>這個是官網中extract()的範例：</p>
<pre class="brush: php;">
  include('pclzip.lib.php');
  $archive = new PclZip('archive.zip');
  if ($archive-&gt;extract(PCLZIP_OPT_PATH, 'data',
                        PCLZIP_OPT_REMOVE_PATH, 'install/release') == 0) {
    //當有錯誤的時候，可以用這個顯示錯誤訊息
    die(&quot;Error : &quot;.$archive-&gt;errorInfo(true));
  }
</pre>
<p>就我剛剛的研究，目前還不行建立有密碼的壓縮檔<br />
不過還是很夠用了～ 推～</p>
<p>參考資訊：<br />
<a href="http://www.phpconcept.net/pclzip/man/en/index.php" target="_blank">PclZip</a> <br />
<a href="http://support.oss.org.tw/?q=node/147" target="_blank">PclZip 簡介與使用</a> <br />
<a href="http://wiki.oss.org.tw/index.php/Php_pclzip_1" target="_blank">TechWiki:PclZip</a> </p>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hsin.tw/2008/php-pclzip/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
