<?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>axing's blog &#187; PHP</title>
	<atom:link href="http://xing.web.id/blog/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://xing.web.id/blog</link>
	<description>Renew, reload, re-新の空</description>
	<lastBuildDate>Wed, 24 Jun 2009 13:14:49 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>PHP.JS &#8211; Use PHP functions in JavaScript</title>
		<link>http://xing.web.id/blog/2009/02/phpjs-use-php-functions-in-javascript/</link>
		<comments>http://xing.web.id/blog/2009/02/phpjs-use-php-functions-in-javascript/#comments</comments>
		<pubDate>Tue, 03 Feb 2009 06:31:54 +0000</pubDate>
		<dc:creator>axing</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Library]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://xing.web.id/blog/?p=94</guid>
		<description><![CDATA[PHP.JS is an open source project in which to port PHP functions to JavaScript. The library is developed by Kevin van Zonneveld and his contributors, and they have been working hard in adding more functions into it. By including this library into your own web projects, you can use those higher-level PHP functions such as file_get_contents(), [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://phpjs.org/" target="_blank">PHP.JS</a> is an open source project in which to port PHP functions to JavaScript. The library is developed by <a href="http://kevin.vanzonneveld.net/" target="_blank">Kevin van Zonneveld</a> and <a href="http://phpjs.org/authors/index" target="_blank">his contributors</a>, and they have been working hard in adding more functions into it. By including this library into your own web projects, you can use those higher-level PHP functions such as <code>file_get_contents()</code>, <code>mktime()</code>, <code>serialize()</code>, etc which JavaScript doesn't support them natively.</p>
<p>Here is a piece of sample code of PHP's encryption function: <code>base64_encode()</code>:</p>
<div class="code-snippet">
<pre class="javascript"><span style="color: #003366; font-weight: bold;">function</span> base64_encode<span style="color: #66cc66;">&#40;</span> data <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></pre>
<pre class="javascript">&nbsp;</pre>
<pre class="javascript">    <span style="color: #003366; font-weight: bold;">var</span> b64 = <span style="color: #3366CC;">&quot;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=&quot;</span>;</pre>
<pre class="javascript">    <span style="color: #003366; font-weight: bold;">var</span> o1, o2, o3, h1, h2, h3, h4, bits, i = ac = <span style="color: #CC0000;">0</span>, enc=<span style="color: #3366CC;">&quot;&quot;</span>, tmp_arr = <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span>;</pre>
<pre class="javascript">    data = utf8_encode<span style="color: #66cc66;">&#40;</span>data<span style="color: #66cc66;">&#41;</span>;</pre>
<pre class="javascript">&nbsp;</pre>
<pre class="javascript">    <span style="color: #000066; font-weight: bold;">do</span> <span style="color: #66cc66;">&#123;</span></pre>
<pre class="javascript">        o1 = data.<span style="color: #006600;">charCodeAt</span><span style="color: #66cc66;">&#40;</span>i++<span style="color: #66cc66;">&#41;</span>;</pre>
<pre class="javascript">        o2 = data.<span style="color: #006600;">charCodeAt</span><span style="color: #66cc66;">&#40;</span>i++<span style="color: #66cc66;">&#41;</span>;</pre>
<pre class="javascript">        o3 = data.<span style="color: #006600;">charCodeAt</span><span style="color: #66cc66;">&#40;</span>i++<span style="color: #66cc66;">&#41;</span>;</pre>
<pre class="javascript">&nbsp;</pre>
<pre class="javascript">        bits = o1&lt;&lt;<span style="color: #CC0000;">16</span> | o2&lt;&lt;<span style="color: #CC0000;">8</span> | o3;</pre>
<pre class="javascript">&nbsp;</pre>
<pre class="javascript">        h1 = bits&gt;&gt;<span style="color: #CC0000;">18</span> &amp; 0x3f;</pre>
<pre class="javascript">        h2 = bits&gt;&gt;<span style="color: #CC0000;">12</span> &amp; 0x3f;</pre>
<pre class="javascript">        h3 = bits&gt;&gt;<span style="color: #CC0000;">6</span> &amp; 0x3f;</pre>
<pre class="javascript">        h4 = bits &amp; 0x3f;</pre>
<pre class="javascript">&nbsp;</pre>
<pre class="javascript">        tmp_arr<span style="color: #66cc66;">&#91;</span>ac++<span style="color: #66cc66;">&#93;</span> = b64.<span style="color: #006600;">charAt</span><span style="color: #66cc66;">&#40;</span>h1<span style="color: #66cc66;">&#41;</span> + b64.<span style="color: #006600;">charAt</span><span style="color: #66cc66;">&#40;</span>h2<span style="color: #66cc66;">&#41;</span> + b64.<span style="color: #006600;">charAt</span><span style="color: #66cc66;">&#40;</span>h3<span style="color: #66cc66;">&#41;</span> + b64.<span style="color: #006600;">charAt</span><span style="color: #66cc66;">&#40;</span>h4<span style="color: #66cc66;">&#41;</span>;</pre>
<pre class="javascript">    <span style="color: #66cc66;">&#125;</span> <span style="color: #000066; font-weight: bold;">while</span> <span style="color: #66cc66;">&#40;</span>i &lt; data.<span style="color: #006600;">length</span><span style="color: #66cc66;">&#41;</span>;</pre>
<pre class="javascript">&nbsp;</pre>
<pre class="javascript">    enc = tmp_arr.<span style="color: #006600;">join</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">''</span><span style="color: #66cc66;">&#41;</span>;</pre>
<pre class="javascript">&nbsp;</pre>
<pre class="javascript">    <span style="color: #000066; font-weight: bold;">switch</span><span style="color: #66cc66;">&#40;</span> data.<span style="color: #006600;">length</span> % <span style="color: #CC0000;">3</span> <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span></pre>
<pre class="javascript">    <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #CC0000;">1</span>:</pre>
<pre class="javascript">        enc = enc.<span style="color: #006600;">slice</span><span style="color: #66cc66;">&#40;</span><span style="color: #CC0000;">0</span>, <span style="color: #CC0000;">-2</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #3366CC;">'=='</span>;</pre>
<pre class="javascript">    <span style="color: #000066; font-weight: bold;">break</span>;</pre>
<pre class="javascript">    <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #CC0000;">2</span>:</pre>
<pre class="javascript">        enc = enc.<span style="color: #006600;">slice</span><span style="color: #66cc66;">&#40;</span><span style="color: #CC0000;">0</span>, <span style="color: #CC0000;">-1</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #3366CC;">'='</span>;</pre>
<pre class="javascript">    <span style="color: #000066; font-weight: bold;">break</span>;</pre>
<pre class="javascript">    <span style="color: #66cc66;">&#125;</span></pre>
<pre class="javascript">&nbsp;</pre>
<pre class="javascript">    <span style="color: #000066; font-weight: bold;">return</span> enc;</pre>
<pre class="javascript"><span style="color: #66cc66;">&#125;</span></pre>
</div>
<p>The library is available in 2 different packages:</p>
<ul>
<li><a href="http://phpjs.org/compiled/php.namespaced.js" target="_blank">Namespaced</a> (<a href="http://phpjs.org/compiled/php.namespaced.min.js" target="_blank">min</a>/<a href="http://phpjs.org/compiled/php.namespaced.packed.js" target="_blank">packed</a>)- all functions are contained in one object; and</li>
<li><a href="http://phpjs.org/compiled/php.js" target="_blank">Normal</a> (<a href="http://phpjs.org/compiled/php.min.js" target="_blank">min</a>/<a href="http://phpjs.org/compiled/php.packed.js" target="_blank">packed</a>)- just a collection of standalone functions.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://xing.web.id/blog/2009/02/phpjs-use-php-functions-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gregorian to Lunar Calendar Converter</title>
		<link>http://xing.web.id/blog/2008/12/lunar-calendar-converter/</link>
		<comments>http://xing.web.id/blog/2008/12/lunar-calendar-converter/#comments</comments>
		<pubDate>Thu, 25 Dec 2008 06:24:30 +0000</pubDate>
		<dc:creator>axing</dc:creator>
				<category><![CDATA[Small Works]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Lunar Date]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://xing.web.id/blog/?p=74</guid>
		<description><![CDATA[Sometimes I just have the urge to know what the Lunar date of someone's birthday or a Chinese festival when no Chinese calendar is around. And, I am just getting annoyed when my friends keep asking me to help them find an online date converter. So I made it myself and I put it on [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes I just have the urge to know what the Lunar date of someone's birthday or a Chinese festival when no Chinese calendar is around. And, I am just getting annoyed when my friends keep asking me to help them find an online date converter. So I made <a title="Lunar Calendar Converter" href="http://xing.web.id/lunarcal/" target="_blank">it</a> myself and I put it on my <a href="http://xing.web.id/" target="_blank">website</a>.</p>
<p>This <a title="Lunar Calendar Converter" href="http://xing.web.id/lunarcal/" target="_blank">converter </a>helps you to convert a valid Gregorian (Western) date into Lunar (Chinese) date.</p>
<p><a href="http://xing.web.id/lunarcal/" target="_blank"><img class="alignnone size-medium wp-image-75" title="Lunar Calendar Converter" src="http://xing.web.id/blog/wp-content/uploads/2008/12/lunarcal-300x106.gif" alt="Lunar Calendar Converter" width="300" height="106" /></a></p>
<p>Today is Christmas Day, and this small Christmas gift I made just for you. <img src='http://xing.web.id/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Hohoho! Merry Christmas!</p>
]]></content:encoded>
			<wfw:commentRss>http://xing.web.id/blog/2008/12/lunar-calendar-converter/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP: Convert If to Switch</title>
		<link>http://xing.web.id/blog/2008/12/php-convert-if-to-switch/</link>
		<comments>http://xing.web.id/blog/2008/12/php-convert-if-to-switch/#comments</comments>
		<pubDate>Tue, 23 Dec 2008 14:37:52 +0000</pubDate>
		<dc:creator>axing</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tips & Tricks]]></category>

		<guid isPermaLink="false">http://xing.web.id/blog/?p=72</guid>
		<description><![CDATA[I have been being asked by some friends of mine, that is in PHP language how to convert If statement into Switch statement (in some cases, using Switch is for shortening code).
At first, I thought that Switch was just only for 'equal' comparison. But actually it is more than just equal. So I did a [...]]]></description>
			<content:encoded><![CDATA[<p>I have been being asked by some friends of mine, that is in PHP language how to convert <strong>If </strong>statement into <strong>Switch </strong>statement (in some cases, using Switch is for shortening code).</p>
<p>At first, I thought that Switch was just only for 'equal' comparison. But actually it is more than just equal. So I did a search, and I found there is a way that can code Switch just like If. Well, I'm lazy to explain, so let's see the following sample codes of getting Grade from Score:</p>
<p>If statement:</p>
<div class="code-snippet">
<pre class="php"><span style="color: #0000ff;">$score</span>=<span style="color: #cc66cc;">78</span>;</pre>
<pre class="php"><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$score</span>&gt;=<span style="color: #cc66cc;">85</span><span style="color: #66cc66;">&#41;</span>: <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;Grade A&quot;</span>;</pre>
<pre class="php"><span style="color: #b1b100;">elseif</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$score</span>&gt;=<span style="color: #cc66cc;">70</span><span style="color: #66cc66;">&#41;</span>: <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;Grade B&quot;</span>;</pre>
<pre class="php"><span style="color: #b1b100;">elseif</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$score</span>&gt;=<span style="color: #cc66cc;">55</span><span style="color: #66cc66;">&#41;</span>: <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;Grade C&quot;</span>;</pre>
<pre class="php"><span style="color: #b1b100;">elseif</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$score</span>&gt;=<span style="color: #cc66cc;">40</span><span style="color: #66cc66;">&#41;</span>: <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;Grade D&quot;</span>;</pre>
<pre class="php"><span style="color: #b1b100;">else</span>: <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;Grade E&quot;</span>;</pre>
<pre class="php"><span style="color: #b1b100;">endif</span>;</pre>
</div>
<p>Switch statement:</p>
<div class="code-snippet">
<pre class="php"><span style="color: #0000ff;">$score</span>=<span style="color: #cc66cc;">78</span>;</pre>
<pre class="php"><span style="color: #b1b100;">switch</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></pre>
<pre class="php">  <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">$score</span>&gt;=<span style="color: #cc66cc;">85</span>: <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;Grade A&quot;</span>; <span style="color: #b1b100;">break</span>;</pre>
<pre class="php">  <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">$score</span>&gt;=<span style="color: #cc66cc;">70</span>: <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;Grade B&quot;</span>; <span style="color: #b1b100;">break</span>;</pre>
<pre class="php">  <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">$score</span>&gt;=<span style="color: #cc66cc;">55</span>: <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;Grade C&quot;</span>; <span style="color: #b1b100;">break</span>;</pre>
<pre class="php">  <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">$score</span>&gt;=<span style="color: #cc66cc;">40</span>: <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;Grade D&quot;</span>; <span style="color: #b1b100;">break</span>;</pre>
<pre class="php">  <span style="color: #000000; font-weight: bold;">default</span>: <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;Grade E&quot;</span>;</pre>
<pre class="php"><span style="color: #66cc66;">&#125;</span></pre>
</div>
<p>Both code produces same result, that is "Grade B". <img src='http://xing.web.id/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://xing.web.id/blog/2008/12/php-convert-if-to-switch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
