<?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>mrKrich™ &#187; PHP</title>
	<atom:link href="http://beta.mrkrich.com/category/development/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://beta.mrkrich.com</link>
	<description>The happen things around me</description>
	<lastBuildDate>Fri, 09 Sep 2011 08:00:00 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Page Redirection</title>
		<link>http://beta.mrkrich.com/2009/12/page-redirection/</link>
		<comments>http://beta.mrkrich.com/2009/12/page-redirection/#comments</comments>
		<pubDate>Wed, 16 Dec 2009 11:33:21 +0000</pubDate>
		<dc:creator>mrkrich</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://beta.mrkrich.com/?p=197</guid>
		<description><![CDATA[เมื่อวันก่อนมีน้องมาถามเกี่ยวกับเรื่อง Page Redirection ก็เลยคิดว่าจะเอามาเป็นพูดถึงเสียหน่อย
การ redirect หน้าเว็บ คือการส่งหน้าเว็บที่เปิดอยู่ปัจจุบันไปยังหน้าอื่น สามารถทำได้ 3 ระดับดังนี้

ระดับ HTTP Header
ระดับ HTML Header
ระดับ Script


1. ระดับ HTTP Header
เป็นวิธีที่ใช้ได้กับทุก Browser สะดวกรวดเร็ว เพราะไม่จำเป็นจะต้องมีการ render หน้าเว็บ หรือ html tag ใดๆเลย
ตัวอย่างการใช้งาน (PHP)
&#60;?
header(&#8220;location: http://www.google.com&#8221;);
?&#62;
2. ระดับ HTML Header
เป็นวิธีที่ใช้ได้กับทุก Browser เหมือนกับระดับ HTTP Header แต่สามารถใช้ได้กับเว็บที่ไม่ได้ใช้ CGI แต่จะช้ากว่าเนื่องจากใช้ html tag ในการบอก Browser ให้ทำการ redirect
ตัวอย่างการใช้งาน
&#60;html&#62;
&#60;head&#62;
&#60;meta http-equiv=&#8221;refresh&#8221; content=&#8221;2;url=http://www.google.com&#8221;&#62;
&#60;/head&#62;
&#60;/html&#62;
3. ระดับ Script
เป็นวิธีที่นิยมใช้กันมาก เนื่องจากสามารถสร้างเงื่อนไขต่างๆในการทำงานให้กับการ redirect ได้ ซึ่งในวิธีการนี้จะใช้ global object <a href="http://beta.mrkrich.com/2009/12/page-redirection/" class="more-link">More &#62;</a>]]></description>
			<content:encoded><![CDATA[<p>เมื่อวันก่อนมีน้องมาถามเกี่ยวกับเรื่อง Page Redirection ก็เลยคิดว่าจะเอามาเป็นพูดถึงเสียหน่อย</p>
<p>การ redirect หน้าเว็บ คือการส่งหน้าเว็บที่เปิดอยู่ปัจจุบันไปยังหน้าอื่น สามารถทำได้ 3 ระดับดังนี้</p>
<ul>
<li>ระดับ HTTP Header</li>
<li>ระดับ HTML Header</li>
<li>ระดับ Script</li>
</ul>
<p><span id="more-197"></span></p>
<h3>1. ระดับ HTTP Header</h3>
<p>เป็นวิธีที่ใช้ได้กับทุก Browser สะดวกรวดเร็ว เพราะไม่จำเป็นจะต้องมีการ render หน้าเว็บ หรือ html tag ใดๆเลย</p>
<p>ตัวอย่างการใช้งาน (PHP)</p>
<blockquote><p>&lt;?</p>
<p>header(&#8220;location: http://www.google.com&#8221;);</p>
<p>?&gt;</p></blockquote>
<h3>2. ระดับ HTML Header</h3>
<p>เป็นวิธีที่ใช้ได้กับทุก Browser เหมือนกับระดับ HTTP Header แต่สามารถใช้ได้กับเว็บที่ไม่ได้ใช้ CGI แต่จะช้ากว่าเนื่องจากใช้ html tag ในการบอก Browser ให้ทำการ redirect</p>
<p>ตัวอย่างการใช้งาน</p>
<blockquote><p>&lt;html&gt;</p>
<p>&lt;head&gt;</p>
<p>&lt;meta http-equiv=&#8221;refresh&#8221; content=&#8221;2;url=http://www.google.com&#8221;&gt;</p>
<p>&lt;/head&gt;</p>
<p>&lt;/html&gt;</p></blockquote>
<h3>3. ระดับ Script</h3>
<p>เป็นวิธีที่นิยมใช้กันมาก เนื่องจากสามารถสร้างเงื่อนไขต่างๆในการทำงานให้กับการ redirect ได้ ซึ่งในวิธีการนี้จะใช้ global object ที่ชื่อ location และมีวิธีการใช้งาน 2 แบบด้วยกัน</p>
<h4>3.1 แบบ property &#8211; href</h4>
<p>วิธีการนี้เป็นเหมือน link ปกติคือมีการเก็บ history เอาไว้ สามารถกดปุ่ม back กลับมายังหน้าปัจจุบันได้</p>
<blockquote><p>&lt;script type=&#8221;text/javascript&#8221;&gt;</p>
<p>location.href = &#8220;http://www.google.com&#8221;;</p>
<p>&lt;/script&gt;</p></blockquote>
<h4>3.2 แบบ function &#8211; replace</h4>
<p>วิธีนี้เป็นการแทนที่ใน history เดิม ทำให้ไม่สามารถกดปุ่ม back กลับมายังหน้าปัจจุบันได้</p>
<blockquote><p>&lt;script type=&#8221;text/javascript&#8221;&gt;</p>
<p>location.replace(&#8220;http://www.google.com&#8221;);</p>
<p>&lt;/script&gt;</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://beta.mrkrich.com/2009/12/page-redirection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I&#8217;m noob</title>
		<link>http://beta.mrkrich.com/2008/03/im-noob/</link>
		<comments>http://beta.mrkrich.com/2008/03/im-noob/#comments</comments>
		<pubDate>Thu, 06 Mar 2008 09:20:00 +0000</pubDate>
		<dc:creator>mrKrich</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://beta.mrkrich.com/?p=88</guid>
		<description><![CDATA[It&#8217;s closely to 10 years that i coding web application in PHP.  The advantage of its is the text management, easy to read and write code, and power of hash array.
I usually use array in many program or library to store data. And have one case that I never know about it, The &#8220;Array <a href="http://beta.mrkrich.com/2008/03/im-noob/" class="more-link">More &#62;</a>]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s closely to 10 years that i coding web application in PHP.  The advantage of its is the text management, easy to read and write code, and power of hash array.</p>
<p>I usually use array in many program or library to store data. And have one case that I never know about it, The &#8220;Array node removing&#8221;. I usually loop the array and move keep node into new array. Yes! it&#8217;s too waste.. but I don&#8217;t know how can i do for remove node. It have array_pop() and array_shift() but cannot remove specific node.</p>
<p>Today I found the way to do that!!! it just use unset()!!! it never bring up in my brain. Actually unexpected &#8230; and it work !!!!</p>
]]></content:encoded>
			<wfw:commentRss>http://beta.mrkrich.com/2008/03/im-noob/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP lite-weight themes</title>
		<link>http://beta.mrkrich.com/2007/11/php-lite-weight-themes/</link>
		<comments>http://beta.mrkrich.com/2007/11/php-lite-weight-themes/#comments</comments>
		<pubDate>Thu, 08 Nov 2007 14:03:00 +0000</pubDate>
		<dc:creator>mrKrich</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://beta.mrkrich.com/?p=82</guid>
		<description><![CDATA[Hello! It&#8217;s too long time that I didnt update this blog. Today I have new custom lib for php programmer. It&#8217;s lite-weight themes system (for anyone who dont want to use smarty). It may not as good as smarty can do but it&#8217;s easy for designer, They didnt know any structure. just mark where is <a href="http://beta.mrkrich.com/2007/11/php-lite-weight-themes/" class="more-link">More &#62;</a>]]></description>
			<content:encoded><![CDATA[<p>Hello! It&#8217;s too long time that I didnt update this blog. Today I have new custom lib for php programmer. It&#8217;s lite-weight themes system (for anyone who dont want to use smarty). It may not as good as smarty can do but it&#8217;s easy for designer, They didnt know any structure. just mark where is for content with &#8220;${}&#8221;.</p>
<blockquote style="overflow: auto; height: 250px;"><pre>&lt;?php

/*write by. mrKrich (Bhanu Thangpulphol)email: mrkrich@msn.com*/

class themes{

private $filename    =    "";private $rawdata    =    "";private $cache        =    "";private $cachemd5    =    "";private $mapping    =    Array();

public function __construct($filename){  $this->setTemplate($filename);}

public function setTemplate($filename){  $this->filename    =    $filename;  $this->rawdata    =    join("", file($filename));  $this->cachemd5    =    md5($this->rawdata);  preg_match_all("/\\$\{([^\}]+)\}/Ui", $this->rawdata, $res);  foreach($res[1] as $r){      $this->mapping[$r] = "";  }}

public function setMap($key, $value){  $this->mapping[$key] = $value;}

public function clearMap(){  $this->mapping = Array();}

public function clearCache(){  $this->cache    =    "";  $this->cachemd5    =    "";}

private function map(){  $res = $this->rawdata;  foreach($this->mapping as $i=>$d){      $res = str_replace("\${" . $i . "}", $d, $res);  }  return $res;}

private function checkversion(){  $md5 = md5($this->rawdata . print_r($this->mapping, true));  return ($this->cachemd5 == $md5);}

private function merge(){  if(!$this->checkversion() &amp;&amp; $this->cache==""){      $res = $this->map();      $this->cache = $res;      $this->cachemd5 = md5($this->rawdata . print_r($this->mapping, true));  }  return $this->cache;}

public function __toString(){  return $this->merge();}

}

?&gt;</pre>
</blockquote>
<p>you also can <a href="http://www.mrkrich.com/mylibs/themes.lib.zip">download</a> , modify or use anywhere but please reference to me (for the based code) and you (for your changed code).</p>
]]></content:encoded>
			<wfw:commentRss>http://beta.mrkrich.com/2007/11/php-lite-weight-themes/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>the overlook function</title>
		<link>http://beta.mrkrich.com/2007/02/the-overlook-function/</link>
		<comments>http://beta.mrkrich.com/2007/02/the-overlook-function/#comments</comments>
		<pubDate>Fri, 09 Feb 2007 18:03:00 +0000</pubDate>
		<dc:creator>mrKrich</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://beta.mrkrich.com/?p=72</guid>
		<description><![CDATA[I used to talk about font encoding, I used header() to solve it. Today I found another function to convert the encoding, It&#8217;s iconv().
When I finding for encoding converter. I proof reading all and pass the unknown and unrelated topic. iconv is one of it. Because I think it be the function about &#8220;icon&#8221; &#8230; <a href="http://beta.mrkrich.com/2007/02/the-overlook-function/" class="more-link">More &#62;</a>]]></description>
			<content:encoded><![CDATA[<p>I used to talk about <a href="http://blog.mrkrich.com/2007/02/http-header.html">font encoding</a>, I used <a href="http://www.php.net/manual/en/function.header.php">header()</a> to solve it. Today I found another function to convert the encoding, It&#8217;s <a href="http://www.google.com/url?sa=t&#038;ct=res&amp;cd=1&#038;url=http%3A%2F%2Fwww.php.net%2Ficonv&amp;ei=6LjMRbf0DJjisAL40vzjAw&#038;usg=__HDBpgn4idQjVyu3EgP84iBFXV0Y=&amp;sig2=-vNy1fG72zvQgYfPkPHz1w">iconv()</a>.</p>
<p>When I finding for encoding converter. I proof reading all and pass the unknown and unrelated topic. iconv is one of it. Because I think it be the function about &#8220;icon&#8221; &#8230; yes icon, an images link/reference to any program or function.</p>
<p><a href="http://en.wikipedia.org/wiki/Iconv">Iconv</a> is the standard programming interface for converting <a href="http://en.wikipedia.org/wiki/Character_string" title="Character string">character strings</a> from one character encoding to another in <a href="http://en.wikipedia.org/wiki/Unix-like" title="Unix-like">Unix-like</a> operating systems.</p>
<p>In php it&#8217;s so easy to use like this<br />
<blockquote>$utf8_string = iconv(&#8220;TIS-620&#8243;, &#8220;UTF-8&#8243;, $tis620_string);</p></blockquote>
<p>Is it easy?</p>
]]></content:encoded>
			<wfw:commentRss>http://beta.mrkrich.com/2007/02/the-overlook-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HTTP Header</title>
		<link>http://beta.mrkrich.com/2007/02/http-header/</link>
		<comments>http://beta.mrkrich.com/2007/02/http-header/#comments</comments>
		<pubDate>Thu, 01 Feb 2007 18:14:00 +0000</pubDate>
		<dc:creator>mrKrich</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://beta.mrkrich.com/?p=69</guid>
		<description><![CDATA[on my testing web. I try to use AJAX on my site and found some error if i use non unicode. may be my page encoding or somethings wrong behind the protocol.
so i try to use UTF-8  for this problem. So i found another problem to solve!!!
i put this line on my HTML



it found, <a href="http://beta.mrkrich.com/2007/02/http-header/" class="more-link">More &#62;</a>]]></description>
			<content:encoded><![CDATA[<p>on my testing web. I try to use AJAX on my site and found some error if i use non unicode. may be my page encoding or somethings wrong behind the protocol.</p>
<p>so i try to use UTF-8  for this problem. So i found another problem to solve!!!</p>
<p>i put this line on my HTML<br />
<blockquote>
<pre id="line1"><<span class="start-tag">meta</span><span class="attribute-name"> http-equiv</span>=<span class="attribute-value">Content-Type </span><span class="attribute-name">content</span>=<span class="attribute-value">"text/html; charset=UTF-8"</span>/></pre>
</blockquote>
<p>it found, but not set my page to UTF-8 as set!! (You can check with page info in firefox)<br />after search in too many site i found something.<br />My web server was set default charset/encoding to ISO8859-11 / TIS-620 / WIndows-874/ CP874 (Thai)<br />so i have only two choice to do.  Change web server setting or customize http header</p>
<p>I&#8217;ll not talk to change default web server configuration for charset/encoding so i will talk about how to customize http header</p>
<p>php: use command <a href="http://www.php.net/manual/en/function.header.php">header()</a> to set content-type like this<br />
<blockquote>header(&#8220;Content-Type: text/html; charset=UTF-8;&#8221;);</p></blockquote>
<p>jsp: you usually use this in your code<br />
<blockquote><%@ page language="java" contentType="text/html; charset=UTF-8" %></p></blockquote>
<p>so on another programming language must have its own way to do something like this</p>
]]></content:encoded>
			<wfw:commentRss>http://beta.mrkrich.com/2007/02/http-header/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

