<?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>Learning Is Fun</title>
	<atom:link href="http://www.tanzilo.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tanzilo.com</link>
	<description>Talks on Web Technology and Better Product Development</description>
	<lastBuildDate>Sat, 29 Jan 2011 22:03:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>PHP: Convert number &amp; currency to text in asian i.e. Bangladeshi, Indian format</title>
		<link>http://www.tanzilo.com/2011/01/28/php-convert-number-currency-to-text-in-asian-i-e-bangladeshi-indian-format/</link>
		<comments>http://www.tanzilo.com/2011/01/28/php-convert-number-currency-to-text-in-asian-i-e-bangladeshi-indian-format/#comments</comments>
		<pubDate>Fri, 28 Jan 2011 15:45:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.tanzilo.com/?p=112</guid>
		<description><![CDATA[Hello Guys, I am from Bangladesh and our currency system is somewhat different. We use lac/lakh, crore etc. So, today I had to convert number to word in a project. When I was searching the web, I did not found anything that meets my requirement 100%. So I wrote one. Although my code does not [...]]]></description>
			<content:encoded><![CDATA[<p>Hello Guys,</p>
<p>I am from Bangladesh and our currency system is somewhat different. We use lac/lakh, crore etc. So, today I had to convert number to word in a project. When I was searching the web, I did not found anything that meets my requirement 100%. So I wrote one. Although my code does not support more than 999 crore taka / rupee, I think this will suffice most of the projects requirements.</p>
<p>To be frank I used several pieces of beautiful code from internet.</p>
<p>Well. Enough talks. Let me show the code.</p>
<p>CODE:</p>
<p>================================================</p>
<p>{code type=PHP}</p>
<p><?php</p>
<p>	error_reporting(E_ALL);<br />
	//error_reporting(0);</p>
<p>	class Currency<br />
	{</p>
<p>		function __construct()<br />
		{<br />
			//do nothing for now<br />
		}</p>
<p>		// http://www.phpbuilder.com/board/showthread.php?t=10350901<br />
		function get_bd_money_format($amount)<br />
		{<br />
			$output_string = '';<br />
			$fraction = '';<br />
			$tokens = explode('.', $amount);<br />
			$number = $tokens[0];<br />
			if(count($tokens) > 1)<br />
			{<br />
				$fraction = (double)(&#8217;0.&#8217; . $tokens[1]);<br />
				$fraction = $fraction * 100;<br />
				$fraction = round($fraction, 0);<br />
				$fraction = &#8216;.&#8217; . $fraction;<br />
			}</p>
<p>			$number = $number . &#8221;;<br />
			$spl=str_split($number);<br />
			$lpcount=count($spl);<br />
			$rem=$lpcount-3;<br />
			//echo &#8220;rem&#8221;.$rem.&#8221;<br/>&#8220;;<br />
			//even one<br />
			if($lpcount%2==0)<br />
			{<br />
				for($i=0;$i<=$lpcount-1;$i++)<br />
				{</p>
<p>					if($i%2!=0 &#038;&#038; $i!=0 &#038;&#038; $i!=$lpcount-1)<br />
					{<br />
						$output_string .= ",";<br />
					}<br />
					$output_string .= $spl[$i];<br />
				}<br />
			}<br />
			//odd one<br />
			if($lpcount%2!=0)<br />
			{<br />
				for($i=0;$i<=$lpcount-1;$i++)<br />
				{<br />
					if($i%2==0 &#038;&#038; $i!=0 &#038;&#038; $i!=$lpcount-1)<br />
					{<br />
						$output_string .= ",";<br />
					}<br />
					$output_string .= $spl[$i];<br />
				}<br />
			}<br />
			return $output_string . $fraction;<br />
		}</p>
<p>		// http://efreedom.com/Question/1-3181945/Convert-Money-Text-PHP<br />
		function translate_to_words($number)<br />
		{<br />
		/*****<br />
			 * A recursive function to turn digits into words<br />
			 * Numbers must be integers from -999,999,999,999 to 999,999,999,999 inclussive.<br />
			 *<br />
			 *  (C) 2010 Peter Ajtai<br />
			 *    This program is free software: you can redistribute it and/or modify<br />
			 *    it under the terms of the GNU General Public License as published by<br />
			 *    the Free Software Foundation, either version 3 of the License, or<br />
			 *    (at your option) any later version.<br />
			 *<br />
			 *    This program is distributed in the hope that it will be useful,<br />
			 *    but WITHOUT ANY WARRANTY; without even the implied warranty of<br />
			 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the<br />
			 *    GNU General Public License for more details.<br />
			 *<br />
			 *    See the GNU General Public License: <http://www.gnu.org/licenses/>.<br />
			 *<br />
			 */<br />
			// zero is a special case, it cause problems even with typecasting if we don&#8217;t deal with it here<br />
			$max_size = pow(10,18);<br />
			if (!$number) return &#8220;zero&#8221;;<br />
			if (is_int($number) &#038;&#038; $number < abs($max_size))<br />
			{<br />
				$prefix = '';<br />
				$suffix = '';<br />
				switch ($number)<br />
				{<br />
					// set up some rules for converting digits to words<br />
					case $number < 0:<br />
						$prefix = "negative";<br />
						$suffix = $this->translate_to_words(-1*$number);<br />
						$string = $prefix . &#8221; &#8221; . $suffix;<br />
						break;<br />
					case 1:<br />
						$string = &#8220;one&#8221;;<br />
						break;<br />
					case 2:<br />
						$string = &#8220;two&#8221;;<br />
						break;<br />
					case 3:<br />
						$string = &#8220;three&#8221;;<br />
						break;<br />
					case 4:<br />
						$string = &#8220;four&#8221;;<br />
						break;<br />
					case 5:<br />
						$string = &#8220;five&#8221;;<br />
						break;<br />
					case 6:<br />
						$string = &#8220;six&#8221;;<br />
						break;<br />
					case 7:<br />
						$string = &#8220;seven&#8221;;<br />
						break;<br />
					case 8:<br />
						$string = &#8220;eight&#8221;;<br />
						break;<br />
					case 9:<br />
						$string = &#8220;nine&#8221;;<br />
						break;<br />
					case 10:<br />
						$string = &#8220;ten&#8221;;<br />
						break;<br />
					case 11:<br />
						$string = &#8220;eleven&#8221;;<br />
						break;<br />
					case 12:<br />
						$string = &#8220;twelve&#8221;;<br />
						break;<br />
					case 13:<br />
						$string = &#8220;thirteen&#8221;;<br />
						break;<br />
					// fourteen handled later<br />
					case 15:<br />
						$string = &#8220;fifteen&#8221;;<br />
						break;<br />
					case $number < 20:<br />
						$string = $this->translate_to_words($number%10);<br />
						// eighteen only has one &#8220;t&#8221;<br />
						if ($number == 18)<br />
						{<br />
						$suffix = &#8220;een&#8221;;<br />
						} else<br />
						{<br />
						$suffix = &#8220;teen&#8221;;<br />
						}<br />
						$string .= $suffix;<br />
						break;<br />
					case 20:<br />
						$string = &#8220;twenty&#8221;;<br />
						break;<br />
					case 30:<br />
						$string = &#8220;thirty&#8221;;<br />
						break;<br />
					case 40:<br />
						$string = &#8220;forty&#8221;;<br />
						break;<br />
					case 50:<br />
						$string = &#8220;fifty&#8221;;<br />
						break;<br />
					case 60:<br />
						$string = &#8220;sixty&#8221;;<br />
						break;<br />
					case 70:<br />
						$string = &#8220;seventy&#8221;;<br />
						break;<br />
					case 80:<br />
						$string = &#8220;eighty&#8221;;<br />
						break;<br />
					case 90:<br />
						$string = &#8220;ninety&#8221;;<br />
						break;<br />
					case $number < 100:<br />
						$prefix = $this->translate_to_words($number-$number%10);<br />
						$suffix = $this->translate_to_words($number%10);<br />
						//$string = $prefix . &#8220;-&#8221; . $suffix;<br />
						$string = $prefix . &#8221; &#8221; . $suffix;<br />
						break;<br />
					// handles all number 100 to 999<br />
					case $number < pow(10,3):<br />
						// floor return a float not an integer<br />
						$prefix = $this->translate_to_words(intval(floor($number/pow(10,2)))) . &#8221; hundred&#8221;;<br />
						if ($number%pow(10,2)) $suffix = &#8221; and &#8221; . $this->translate_to_words($number%pow(10,2));<br />
						$string = $prefix . $suffix;<br />
						break;<br />
					case $number < pow(10,6):<br />
						// floor return a float not an integer<br />
						$prefix = $this->translate_to_words(intval(floor($number/pow(10,3)))) . &#8221; thousand&#8221;;<br />
						if ($number%pow(10,3)) $suffix = $this->translate_to_words($number%pow(10,3));<br />
						$string = $prefix . &#8221; &#8221; . $suffix;<br />
						break;<br />
				}<br />
			} else<br />
			{<br />
				echo &#8220;ERROR with &#8211; $number<br/> Number must be an integer between -&#8221; . number_format($max_size, 0, &#8220;.&#8221;, &#8220;,&#8221;) . &#8221; and &#8221; . number_format($max_size, 0, &#8220;.&#8221;, &#8220;,&#8221;) . &#8221; exclussive.&#8221;;<br />
			}<br />
			return $string;<br />
		}</p>
<p>		function get_bd_amount_in_text($amount)<br />
		{<br />
			$output_string = &#8221;;</p>
<p>			$tokens = explode(&#8216;.&#8217;, $amount);<br />
			$current_amount = $tokens[0];<br />
			$fraction = &#8221;;<br />
			if(count($tokens) > 1)<br />
			{<br />
				$fraction = (double)(&#8217;0.&#8217; . $tokens[1]);<br />
				$fraction = $fraction * 100;<br />
				$fraction = round($fraction, 0);<br />
				$fraction = (int)$fraction;<br />
				$fraction = $this->translate_to_words($fraction) . &#8216; paisa&#8217;;<br />
				$fraction = &#8216; Taka &#038; &#8216; . $fraction;<br />
			}</p>
<p>			$crore = 0;<br />
			if($current_amount >= pow(10,7))<br />
			{<br />
				$crore = (int)floor($current_amount / pow(10,7));<br />
				$output_string .= $this->translate_to_words($crore) . &#8216; crore &#8216;;<br />
				$current_amount = $current_amount &#8211; $crore * pow(10,7);<br />
			}</p>
<p>			$lakh = 0;<br />
			if($current_amount >= pow(10,5))<br />
			{<br />
				$lakh = (int)floor($current_amount / pow(10,5));<br />
				$output_string .= $this->translate_to_words($lakh) . &#8216; lakh &#8216;;<br />
				$current_amount = $current_amount &#8211; $lakh * pow(10,5);<br />
			}</p>
<p>			$current_amount = (int)$current_amount;<br />
			$output_string .= $this->translate_to_words($current_amount);</p>
<p>			$output_string = $output_string . $fraction . &#8216; only&#8217;;<br />
			$output_string = ucwords($output_string);<br />
			return $output_string;<br />
		}</p>
<p>	}</p>
<p>	$currency_object = new Currency();</p>
<p>	for($i=1; $i<10; $i++)<br />
	{<br />
		$seed = time() / ($i + 1);<br />
		srand($seed);<br />
		$amount = mt_rand(100, 9999999);<br />
		$amount = $amount + $i/10;<br />
		echo $currency_object->get_bd_money_format($amount) . &#8216; : &#8216; . $currency_object->get_bd_amount_in_text($amount) . &#8216;<br />&#8216;;</p>
<p>	}</p>
<p>?></p>
<p>{/code}</p>
<p>Sample Output:</p>
<p>================================================</p>
<div id="_mcePaste">84,20,202.10 : Eighty Four Lakh Twenty Thousand Two Hundred And Two Taka &amp; Ten Paisa Only</div>
<div id="_mcePaste">10,90,495.20 : Ten Lakh Ninety Thousand Four Hundred And Ninety Five Taka &amp; Twenty Paisa Only</div>
<div id="_mcePaste">12,51,706.30 : Twelve Lakh Fifty One Thousand Seven Hundred And Six Taka &amp; Thirty Paisa Only</div>
<div id="_mcePaste">78,31,550.40 : Seventy Eight Lakh Thirty One Thousand Five Hundred And Fifty Taka &amp; Forty Paisa Only</div>
<div id="_mcePaste">49,59,035.50 : Forty Nine Lakh Fifty Nine Thousand Thirty Five Taka &amp; Fifty Paisa Only</div>
<div id="_mcePaste">29,83,538.60 : Twenty Nine Lakh Eighty Three Thousand Five Hundred And Thirty Eight Taka &amp; Sixty Paisa Only</div>
<div id="_mcePaste">50,70,303.70 : Fifty Lakh Seventy Thousand Three Hundred And Three Taka &amp; Seventy Paisa Only</div>
<div id="_mcePaste">11,98,440.80 : Eleven Lakh Ninety Eight Thousand Four Hundred And Forty Taka &amp; Eighty Paisa Only</div>
<div id="_mcePaste">70,08,871.90 : Seventy Lakh Eight Thousand Eight Hundred And Seventy One Taka &amp; Ninety Paisa Only</div>
<p>================================================</p>
<p>That&#8217;s it!</p>
<p>Please feel free to use this code anytime anywhere.</p>
<p>If you update/enhance this code, please share with other people.</p>
<p>Thanks for reading.</p>
<p><map name='google_ad_map_112_eaab367e2f0158c1'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/112?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_112_eaab367e2f0158c1' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=112&amp;url= http%3A%2F%2Fwww.tanzilo.com%2F2011%2F01%2F28%2Fphp-convert-number-currency-to-text-in-asian-i-e-bangladeshi-indian-format%2F' /></p>]]></content:encoded>
			<wfw:commentRss>http://www.tanzilo.com/2011/01/28/php-convert-number-currency-to-text-in-asian-i-e-bangladeshi-indian-format/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>JavaScript: Div &amp; Element hide &amp; show cross-browser script solution</title>
		<link>http://www.tanzilo.com/2009/01/17/javascript-div-element-hide-show-cross-browser-script-solution/</link>
		<comments>http://www.tanzilo.com/2009/01/17/javascript-div-element-hide-show-cross-browser-script-solution/#comments</comments>
		<pubDate>Sat, 17 Jan 2009 22:17:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[cross-browser]]></category>
		<category><![CDATA[DIV]]></category>
		<category><![CDATA[Element]]></category>
		<category><![CDATA[hide]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[show]]></category>
		<category><![CDATA[solution]]></category>

		<guid isPermaLink="false">http://www.tanzilo.com/?p=75</guid>
		<description><![CDATA[Hello Guys, Today I was working in a project where I had to add element hide and show depending on the condition. For example, if the client wants to contact by phone, the phone DIV element or area appears. If not, the phone DIV element hide quickly. I was writing scripts for this. But to [...]]]></description>
			<content:encoded><![CDATA[<p>Hello Guys,</p>
<p>Today I was working in a project where I had to add element hide and show depending on the condition. For example, if the client wants to contact by phone, the phone DIV element or area appears. If not, the phone DIV element hide quickly. I was writing scripts for this. But to my surprise, I noticed that none of them are cross-browser supporting. When one scripting working in few browsers, the same script is not working in other browsers. So, I struggled to come up with the cross-browser solution and at last, I succeeded. You can use this code in your form whenever you need to show and hide elements dynamically in JavaScript. This script is a kind of Contact Us form.</p>
<p>So, what am I gonna do? I am going to share my small script so that you can save your time I you find my this article by Google search or any other search.</p>
<p>OK!<br />
No more introduction. Let us start.</p>
<p><span style="text-decoration: underline;"><strong>Download:</strong></span></p>
<p>I suggest you first download the script and take a look.<br />
<a title="JavaScript Hide &amp; Show/Display" href="http://www.tanzilo.com/demo/code/hide_show/hide_show.zip" target="_blank">http://www.tanzilo.com/demo/code/hide_show/hide_show.zip</a></p>
<p><span style="text-decoration: underline;"><strong>Features:</strong></span></p>
<ol>
<li>It is a totally CSS-based and table-less scripting</li>
<li>I have used phpMailer version 2.3 and it works for PHP 5 and/or 6 version</li>
<li>JavaScript used as you already know</li>
</ol>
<p><span style="text-decoration: underline;"><strong>CSS Code:</strong></span></p>
<p>{code type=CSS}</p>
<style type="text/css">
	body
	{
		font-family:Tahoma, Verdana, Arial, Helvetica, sans-serif;
		font-size:12px;
	}
	#contactForm
	{
		width:500px; height:auto; float:left; clear:both;
	}
	#contactForm INPUT, OPTION, TEXTAREA
	{
		font-family:Tahoma, Verdana, Arial, Helvetica, sans-serif;
		font-size:12px;
	}
	#formRow
	{
		width:500px; float:left; padding:3px 0px 0px 0px;
	}
	#columnLeft
	{
		width:250px; height:auto; float:left;
	}
	#columnRight
	{
		width:250px; height:auto; float:left;
	}
	#formOutput
	{
	}
	#errorMessage
	{
		color:#FF0000; font-weight:bold;
	}
	#successMessage
	{
		color:#009900; font-weight:bold;
	}
	#formRowForum
	{
		width:500px; float:left; padding:3px 0px 0px 0px;
	}
	#formRowDatabase
	{
		width:500px; float:left; padding:3px 0px 0px 0px;
	}
	#formRowUsers
	{
		width:500px; float:left; padding:3px 0px 0px 0px;
	}
	#formRowProvider
	{
		width:500px; float:left; padding:3px 0px 0px 0px;
	}
	#formRowCurrentSpecs
	{
		width:500px; float:left; padding:3px 0px 0px 0px;
	}
</style>
<p>{/code}</p>
<p><span style="text-decoration: underline;"><strong>HTML Code:</strong></span></p>
<p>{code type=HTML}</p>
<form id="contact_form" name="contact_form" method="post" action="">
<div id="contactForm">
<div id="formRow">
<div id="columnLeft">Name:</div>
<div id="columnRight">
<input name="name" type="text" value="<?php echo $_SESSION['name']; ?>&#8221; /></div>
</p></div>
<div id="formRow">
<div id="columnLeft">Email:</div>
<div id="columnRight">
<input name="email" type="text" value="<?php echo $_SESSION['email']; ?>&#8221; /></div>
</p></div>
<div id="formRow">
<div id="columnLeft">Best method to contact you:</div>
<div id="columnRight">
<select name="contact_method" id="contact_method" onchange="displayContactMethod();">
<option value="Please Select One">Please Select One</option>
<option value="Phone">Phone</option>
</select>
<div id="phoneNoDiv">Phone No:<br />
<input name="phone" id="phone" type="text" value="<?php echo $_SESSION['phone'] ;?>&#8221; /></div>
</p></div>
</p></div>
<div id="formRow">
<div id="columnLeft">Will this server host a vBulletin site?</div>
<div id="columnRight">
<select name="host_vb" id="host_vb" onchange="controlServerHostOptions();">
<option value="No">No</option>
<option value="Yes">Yes</option>
</select></div>
</p></div>
<div id="formRowForum">
<div id="columnLeft">Forum Link:</div>
<div id="columnRight">
<input name="forum_link" type="text" value="<?php echo $_SESSION['forum_link'] ;?>&#8221; /></div>
</p></div>
<div id="formRowDatabase">
<div id="columnLeft">Current size of database:</div>
<div id="columnRight">
<input name="size" type="text" value="<?php echo $_SESSION['size']; ?>&#8221; /></div>
</p></div>
<div id="formRowUsers">
<div id="columnLeft">Average concurrent users:</div>
<div id="columnRight">
<input name="users" type="text" value="<?php echo $_SESSION['users']; ?>&#8221; /></div>
</p></div>
<div id="formRow">
<div id="columnLeft">Do you currently have a dedicated server?</div>
<div id="columnRight">
<select name="server" id="server" onchange="controlCurrentHostOptions();">
<option value="No">No</option>
<option value="Yes">Yes</option>
</select></div>
</p></div>
<div id="formRowProvider">
<div id="columnLeft">Current Provider:</div>
<div id="columnRight">
<input name="current_provider" type="text" value="<?php echo $_SESSION['current_provider']; ?>&#8221; /></div>
</p></div>
<div id="formRowCurrentSpecs">
<div id="columnLeft">Current Server Specs:</div>
<div id="columnRight"><textarea name="current_specs" cols="30" rows="5"><?php echo $_SESSION['current_specs'] ;?></textarea></div>
</p></div>
<div id="formRow">
<div id="columnLeft">Are there any specs you must have with your new server<br />
            or additional notes you would like us to consider?</div>
<div id="columnRight"><textarea name="specs" cols="30" rows="5"><?php echo $_SESSION['specs']; ?></textarea></div>
</p></div>
<div id="formRow">
<div id="columnLeft">Time frame to purchase</div>
<div id="columnRight">
<input name="time" type="text" value="<?php echo $_SESSION['time']; ?>&#8221; /></div>
</p></div>
<div id="formRow">
<div id="columnLeft">Do you have a budget we need to consider?</div>
<div id="columnRight">
<input name="budget" type="text" value="<?php echo $_SESSION['budget']; ?>&#8221; /></div>
</p></div>
<div id="formRow">
<div id="columnLeft">Anti Spam Question: How much is: 5+5+3=?</div>
<div id="columnRight">
<input name="total" type="text" /></div>
</p></div>
<div id="formRow">
<div id="columnLeft">&nbsp;</div>
<div id="columnRight">
<input name="submit" type="submit" value="Submit" />
<input name="reset" type="reset" />
        	</div>
</p></div>
</p></div>
</form>
<p>{/code}</p>
<p><span style="text-decoration: underline;"><strong>JavaScript Code:</strong></span></p>
<p>{code type=JavaScript}</p>
<p>	function displayContactMethod()<br />
	{<br />
		var id = &#8216;phone&#8217;;<br />
		var contatMethod = document.contact_form.contact_method.value;</p>
<p>		if(contatMethod == &#8220;Phone&#8221;)<br />
		{<br />
			displayDiv(&#8216;phoneNoDiv&#8217;)<br />
		}<br />
		else<br />
		{<br />
			hideDiv(&#8216;phoneNoDiv&#8217;);<br />
			document.contact_form.phone.value = &#8221;;<br />
		}<br />
	}</p>
<p>	function initialHiddenDivs()<br />
	{<br />
		var divID_1 = &#8216;phoneNoDiv&#8217;;<br />
		var divID_2 = &#8216;formRowForum&#8217;;<br />
		var divID_3 = &#8216;formRowDatabase&#8217;;<br />
		var divID_4 = &#8216;formRowUsers&#8217;;<br />
		var divID_5 = &#8216;formRowProvider&#8217;;<br />
		var divID_6 = &#8216;formRowCurrentSpecs&#8217;;</p>
<p>		hideDiv(divID_1);<br />
		hideDiv(divID_2);<br />
		hideDiv(divID_3);<br />
		hideDiv(divID_4);<br />
		hideDiv(divID_5);<br />
		hideDiv(divID_6);<br />
	}<br />
	function hideDiv(id)<br />
	{<br />
		if (document.getElementById) { // DOM3 = IE5, NS6<br />
			document.getElementById(id).style.display = &#8216;none&#8217;;<br />
		}<br />
		else {<br />
			if (document.layers) { // Netscape 4<br />
				document.id.display = &#8216;none&#8217;;<br />
			}<br />
			else { // IE 4<br />
				document.all.id.style.display = &#8216;none&#8217;;<br />
			}<br />
		}<br />
	}</p>
<p>	function displayDiv(id)<br />
	{<br />
		if (document.getElementById) { // DOM3 = IE5, NS6<br />
			document.getElementById(id).style.display = &#8216;block&#8217;;<br />
		}<br />
		else {<br />
			if (document.layers) { // Netscape 4<br />
				document.id.display = &#8216;block&#8217;;<br />
			}<br />
			else { // IE 4<br />
				document.all.id.style.display = &#8216;block&#8217;;<br />
			}<br />
		}<br />
	}</p>
<p>	function controlServerHostOptions()<br />
	{<br />
		var host_vb = document.contact_form.host_vb.value;</p>
<p>		if(host_vb == &#8220;Yes&#8221;)<br />
		{<br />
			displayDiv(&#8216;formRowForum&#8217;);<br />
			displayDiv(&#8216;formRowDatabase&#8217;);<br />
			displayDiv(&#8216;formRowUsers&#8217;);<br />
		}<br />
		else<br />
		{<br />
			hideDiv(&#8216;formRowForum&#8217;);<br />
			hideDiv(&#8216;formRowDatabase&#8217;);<br />
			hideDiv(&#8216;formRowUsers&#8217;);<br />
			document.contact_form.forum_link.value = &#8221;;<br />
			document.contact_form.size.value = &#8221;;<br />
			document.contact_form.users.value = &#8221;;<br />
		}<br />
	}</p>
<p>	function controlCurrentHostOptions()<br />
	{<br />
		var server = document.contact_form.server.value;</p>
<p>		if(server == &#8220;Yes&#8221;)<br />
		{<br />
			displayDiv(&#8216;formRowProvider&#8217;);<br />
			displayDiv(&#8216;formRowCurrentSpecs&#8217;);<br />
		}<br />
		else<br />
		{<br />
			hideDiv(&#8216;formRowProvider&#8217;);<br />
			hideDiv(&#8216;formRowCurrentSpecs&#8217;);<br />
			document.contact_form.current_provider.value = &#8221;;<br />
			document.contact_form.current_specs.value = &#8221;;<br />
		}<br />
	}</p>
<p>{/code}</p>
<p><span style="text-decoration: underline;"><strong>PHP Code:</strong></span></p>
<p>{code type=PHP}<br />
	<?php		</p>
<p>		if($_POST)<br />
		{</p>
<p>			$name 				= trim($_POST['name']);<br />
			$email 				= trim($_POST['email']);<br />
			$contact_method 	= trim($_POST['contact_method']);<br />
			$phone 				= trim($_POST['phone']);<br />
			$host_vb 			= trim($_POST['host_vb']);<br />
			$forum_link 		= trim($_POST['forum_link']);<br />
			$size 				= trim($_POST['size']);<br />
			$users 				= trim($_POST['users']);<br />
			$server 			= trim($_POST['server']);<br />
			$current_provider 	= trim($_POST['current_provider']);<br />
			$current_specs 		= trim($_POST['current_specs']);<br />
			$specs 				= trim($_POST['specs']);<br />
			$time 				= trim($_POST['time']);<br />
			$budget 			= trim($_POST['budget']);<br />
			$total	 			= trim($_POST['total']);</p>
<p>			$_SESSION['name']				= $name;<br />
			$_SESSION['email']				= $email;<br />
			$_SESSION['contact_method']		= $contact_method;<br />
			$_SESSION['phone']				= $phone;<br />
			$_SESSION['host_vb']			= $host_vb;<br />
			$_SESSION['forum_link']			= $forum_link;<br />
			$_SESSION['size']				= $size;<br />
			$_SESSION['users']				= $users;<br />
			$_SESSION['server']				= $server;<br />
			$_SESSION['current_provider']	= $current_provider;<br />
			$_SESSION['current_specs']		= $current_specs;<br />
			$_SESSION['specs']				= $specs;<br />
			$_SESSION['time']				= $time;<br />
			$_SESSION['budget']				= $budget;</p>
<p>			if($total != 13)<br />
			{<br />
					echo '
<div id=errorMessage>Anti Spam Question is wrong!<br />
					Please sum up and type the current result of: 5+5+3=?</div>
<p>&#8216;;<br />
			}<br />
			else<br />
			{</p>
<p>				$emailBody = &#8221;;<br />
				if(!empty($name))<br />
				{<br />
					$emailBody .= &#8216;Name : &#8216; . $name . chr(10);<br />
				}<br />
				if(!empty($email))<br />
				{<br />
					$emailBody .= &#8216;Email : &#8216; . $email . chr(10);<br />
				}<br />
				if(!empty($contact_method))<br />
				{<br />
					$emailBody .= &#8216;Best method to contact you : &#8216; . $contact_method . chr(10);<br />
				}<br />
				if(!empty($phone))<br />
				{<br />
					$emailBody .= &#8216;Phone : &#8216; . $phone . chr(10);<br />
				}<br />
				if(!empty($host_vb))<br />
				{<br />
					$emailBody .= &#8216;Will this server host a vBulletin site? : &#8216; . $host_vb . chr(10);<br />
				}<br />
				if(!empty($forum_link))<br />
				{<br />
					$emailBody .= &#8216;Forum Link : &#8216; . $forum_link . chr(10);<br />
				}<br />
				if(!empty($size))<br />
				{<br />
					$emailBody .= &#8216;Current size of database : &#8216; . $size . chr(10);<br />
				}<br />
				if(!empty($users))<br />
				{<br />
					$emailBody .= &#8216;Average concurrent users : &#8216; . $users . chr(10);<br />
				}<br />
				if(!empty($server))<br />
				{<br />
					$emailBody .= &#8216;Do you currently have a dedicated server? : &#8216; . $server . chr(10);<br />
				}<br />
				if(!empty($current_provider))<br />
				{<br />
					$emailBody .= &#8216;Current Provider : &#8216; . $current_provider . chr(10);<br />
				}<br />
				if(!empty($current_specs))<br />
				{<br />
					$emailBody .= &#8216;Current Server Specs : &#8216; . $current_specs . chr(10);<br />
				}<br />
				if(!empty($specs))<br />
				{<br />
					$emailBody .= &#8216;Are there any specs you must have with your<br />
								   new server or additional notes you would<br />
								   like us to consider? : &#8216; . $specs . chr(10);<br />
				}<br />
				if(!empty($time))<br />
				{<br />
					$emailBody .= &#8216;Time frame to purchase : &#8216; . $time . chr(10);<br />
				}<br />
				if(!empty($budget))<br />
				{<br />
					$emailBody .= &#8216;Do you have a budget we need to consider? : &#8216; . $budget . chr(10);<br />
				}</p>
<p>				include_once(&#8216;php5Mailer/class.phpmailer.php&#8217;);</p>
<p>				$mail = new PHPMailer();</p>
<p>				$body = $emailBody;<br />
				$body = eregi_replace(&#8220;[\]&#8220;,&#8221;,$body);<br />
				$subject = eregi_replace(&#8220;[\]&#8220;,&#8221;,$subject);</p>
<p>				$mail->From = $email;<br />
				$mail->FromName = $name;</p>
<p>				$mail->Subject = &#8220;New Email from $name ($email)&#8221;;</p>
<p>				// optional, comment out and test<br />
				$mail->AltBody = &#8220;To view the message, please use an HTML compatible email viewer!&#8221;; </p>
<p>				$mail->Body = nl2br($body);</p>
<p>				$mail->AddAddress(&#8220;todd@urljet.com&#8221;, &#8220;Todd&#8221;);<br />
				$mail->IsHTML(true);</p>
<p>				if(!$mail->Send())<br />
				{<br />
					echo &#8216;
<div id=errorMessage>Failed to send mail</div>
<p>&#8216;;<br />
				}<br />
				else<br />
				{<br />
					echo &#8216;
<div id=successMessage>Mail sent</div>
<p>&#8216;;<br />
					$_SESSION['name']				= &#8221;;<br />
					$_SESSION['email']				= &#8221;;<br />
					$_SESSION['contact_method']		= &#8221;;<br />
					$_SESSION['phone']				= &#8221;;<br />
					$_SESSION['host_vb']			= &#8221;;<br />
					$_SESSION['forum_link']			= &#8221;;<br />
					$_SESSION['size']				= &#8221;;<br />
					$_SESSION['users']				= &#8221;;<br />
					$_SESSION['server']				= &#8221;;<br />
					$_SESSION['current_provider']	= &#8221;;<br />
					$_SESSION['current_specs']		= &#8221;;<br />
					$_SESSION['specs']				= &#8221;;<br />
					$_SESSION['time']				= &#8221;;<br />
					$_SESSION['budget']				= &#8221;;<br />
				}	</p>
<p>			}</p>
<p>		}</p>
<p>	?><br />
{/code}</p>
<p>Once again I would like to remind you that you first download this small script from the above download link and take a look at the whole script.</p>
<p>That is all for now, Dude!</p>
<p>Thank you for reading.</p>
<p><map name='google_ad_map_75_eaab367e2f0158c1'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/75?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_75_eaab367e2f0158c1' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=75&amp;url= http%3A%2F%2Fwww.tanzilo.com%2F2009%2F01%2F17%2Fjavascript-div-element-hide-show-cross-browser-script-solution%2F' /></p>]]></content:encoded>
			<wfw:commentRss>http://www.tanzilo.com/2009/01/17/javascript-div-element-hide-show-cross-browser-script-solution/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>WordPress: adding a custom option box and developing file upload plugin</title>
		<link>http://www.tanzilo.com/2009/01/15/wordpress-adding-a-custom-option-box-and-developing-file-upload-plugin/</link>
		<comments>http://www.tanzilo.com/2009/01/15/wordpress-adding-a-custom-option-box-and-developing-file-upload-plugin/#comments</comments>
		<pubDate>Thu, 15 Jan 2009 17:54:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[adding]]></category>
		<category><![CDATA[custom option box]]></category>
		<category><![CDATA[developing]]></category>
		<category><![CDATA[file upload]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://www.tanzilo.com/?p=70</guid>
		<description><![CDATA[Hello Buddy, One of my clients wanted to show thumbnail photo beside the post text as below. So, I had to make a plugin so that the admin can post the thumbnail when he is writing the post or can edit when editing the post. Take a look at the thumbnail&#8217;s position below. Thus, recently [...]]]></description>
			<content:encoded><![CDATA[<p>Hello Buddy,</p>
<p>One of my clients wanted to show thumbnail photo beside the post text as below. So, I had to make a plugin so that the admin can post the thumbnail when he is writing the post or can edit when editing the post. Take a look at the thumbnail&#8217;s position below.</p>
<p><a href="http://www.tanzilo.com/wp-content/uploads/2009/01/bag-blog.jpg"><img class="alignleft size-full wp-image-72" style="float:none;" title="bag-blog" src="http://www.tanzilo.com/wp-content/uploads/2009/01/bag-blog.jpg" alt="" width="500" height="237" /></a></p>
<p>Thus, recently I solved a plugin problem in one of my wordpress works although it was small. You know you may sometimes need to add a custom field in your wordpress posting/writing/editing area. To check what I am saying, take a look at the following image:</p>
<p><a href="http://www.tanzilo.com/wp-content/uploads/2009/01/bag-thumbnail-plugin.jpg"><img class="alignleft size-full wp-image-71" style="float:none;" title="bag-thumbnail-plugin" src="http://www.tanzilo.com/wp-content/uploads/2009/01/bag-thumbnail-plugin.jpg" alt="" width="500" height="391" /></a></p>
<p>Adding such a box is extremely easy using the wordpress&#8217;s builtin <strong>add_meta</strong> function. But does file upload works i.e. if you upload the file, will it work? The answer is straight &#8211; &#8220;NO&#8221;. But why? The reason is also simple. If you want to upload a file, your form should have &#8220;<span style="text-decoration: underline;"><strong>enctype=&#8221;multipart/form-data</strong></span>&#8221; in the form opening such as</p>
<p>{code type=HTML}</p>
<form name="post" action="post.php" method="post" id="post" enctype="multipart/form-data">
{/code}</p>
<p>But the problem is &#8211; if you open the source code of text editor tool as following,</p>
<p><a href="http://www.tanzilo.com/wp-content/uploads/2009/01/writing-editing-tool.jpg"><img class="alignleft size-full wp-image-73" style="float:none;" title="writing-editing-tool" src="http://www.tanzilo.com/wp-content/uploads/2009/01/writing-editing-tool.jpg" alt="" width="500" height="315" /></a></p>
<p>you will see that it does not have &#8220;<strong>enctype=&#8221;multipart/form-data</strong>&#8221; unfortunately. It looks exactly like this in my wordpress 2.7 version if I open the <span style="text-decoration: underline;">wp-admin/edit-form-advanced.php</span> file at line # 520.</p>
<p>{code type=HTML}</p>
<form name="post" action="post.php" method="post" id="post">
{/code}</p>
<p>Not funny? Huh?</p>
<p>So, to cope up with this situation, I had to add &#8220;<strong>enctype=&#8221;multipart/form-data</strong>&#8221; in the form although I do not like changing the core files. Why do not I like to change the core files? The answer simple. Because whenever there is an update, the client have to update the file everytime. The client may not like it or may even forget it. Anyway, after change, it looks like this:</p>
<p>{code type=HTML}</p>
<form name="post" action="post.php" method="post" id="post" enctype="multipart/form-data">
{/code}</p>
<p>OK. Lemme show you step by step what to do if you want to add a file upload plugin.</p>
<p><span style="text-decoration: underline;"><strong>Step One: Change the &#8220;wp-admin/edit-form-advanced.php&#8221; file</strong></span></p>
<p>Open this file from the mentioned location and change the following line in the file:</p>
<p>{code type=HTML}</p>
<form name="post" action="post.php" method="post" id="post">
{/code}</p>
<p>to this line:</p>
<p>{code type=HTML}</p>
<form name="post" action="post.php" method="post" id="post" enctype="multipart/form-data">
{/code}</p>
<p><span style="text-decoration: underline;"><strong>Step Two: Write you plugin</strong></span></p>
<p>Here goes mine:</p>
<p>{code type=PHP}<br />
<?php</p>
<p>	/*<br />
	Plugin Name: Bag Thumbnail<br />
	Plugin URI: http://www.tanzilo.com/<br />
	Description: This plugin helps you to set thumbnail image of your bags.<br />
	Author: Tanzil Al Gazmir<br />
	Version: 1.0<br />
	Author URI: http://www.tanzilo.com/<br />
	*/</p>
<p>	function init_bag_review_thumb_widget()<br />
	{</p>
<p>		global $wpdb;</p>
<p>		$result = mysql_list_tables(DB_NAME);<br />
		$current_table = array();<br />
		while($row = mysql_fetch_row($result))<br />
		{<br />
			$current_tables[] = $row[0];<br />
		}<br />
		$myNewDatabaseTable = $wpdb->prefix . &#8216;bag_thumb&#8217;;<br />
		if(!in_array($myNewDatabaseTable, $current_tables))<br />
		{</p>
<p>			mysql_query(&#8221;<br />
			CREATE TABLE IF NOT EXISTS `&#8221; . $myNewDatabaseTable . &#8220;` (<br />
			`id` int(11) NOT NULL auto_increment,<br />
			`post_id` int(11) NOT NULL,<br />
			`image_name` varchar(255) NOT NULL,<br />
			PRIMARY KEY  (`id`)<br />
			);<br />
			&#8220;);<br />
		}</p>
<p>		/*<br />
		// Now I am going to delete all unnecessary thumb images by scanning the<br />
		// whole directory<br />
		*/<br />
		$sqlQuery = &#8220;SELECT image_name FROM &#8221; .$wpdb->prefix . &#8220;bag_thumb; &#8220;;<br />
		$fileArray = $wpdb->get_col($sqlQuery);<br />
		$fileArray[] = &#8216;no_thumb.jpg&#8217;;</p>
<p>		if ($handle = opendir(&#8216;../bag_thumb/&#8217;))<br />
		{</p>
<p>			// This is the correct way to loop over the directory.<br />
			while (false !== ($file = readdir($handle)))<br />
			{<br />
				if(is_file(&#8216;../bag_thumb/&#8217; . $file))<br />
				{<br />
					if(!in_array($file, $fileArray))<br />
					{<br />
						unlink(&#8216;../bag_thumb/&#8217; . $file);<br />
					}<br />
				}<br />
			}</p>
<p>			closedir($handle);<br />
		}</p>
<p>	}</p>
<p>	// This function tells WP to add a new &#8220;meta box&#8221;<br />
	function add_bag_photo_box()<br />
	{</p>
<p>		add_meta_box(</p>
<p>			&#8216;bag_photo&#8217;, // id of the
<div> we&#8217;ll add<br />
			&#8216;Add Bag Thumbnail Photo&#8217;, //title<br />
			&#8216;add_bag_photo&#8217;, // callback function that will echo the box content<br />
			&#8216;post&#8217;, // where to add the box: on &#8220;post&#8221;, &#8220;page&#8221;, or &#8220;link&#8221; page<br />
			&#8216;normal&#8217;,<br />
			&#8216;high&#8217; </p>
<p>		);<br />
	}</p>
<p>	// This function echoes the content of our meta box<br />
	function add_bag_photo()<br />
	{<br />
		echo<br />
			&#8216;<label> Select a thumbnail (150px by 100px) photo for this bag</p>
<input type="file" name="bag_thumbnail_photo" id="bag_thumbnail_photo" />
			 </label></p>
<input name="bag_thumbnail_set" type="hidden" id="bag_thumbnail_set" value="yes" />
			&#8216;;<br />
	}</p>
<p>	function bag_thumbnail_plugin_save_postdata()<br />
	{<br />
		$fileArray = array();<br />
		global $wpdb;</p>
<p>		$file = $_FILES['bag_thumbnail_photo'];<br />
		$fileName = $_FILES['bag_thumbnail_photo']['name'];<br />
		$basename = &#8221;;</p>
<p>		if(!empty($fileName))<br />
		{<br />
			if(isAllowedExtension($_FILES['bag_thumbnail_photo']['name']))<br />
			{</p>
<p>				$postID = $_POST['post_ID'];</p>
<p>				# Do uploading here<br />
				$basename = basename( $_FILES['bag_thumbnail_photo']['name']);<br />
				$basename = str_replace(&#8216; &#8216;, &#8216;_&#8217;, $basename);<br />
				$basename = str_replace(&#8216;-&#8217;, &#8216;_&#8217;, $basename);<br />
				$basename = strtolower($basename);<br />
				$basename = $_POST['post_ID'] . &#8216;_&#8217; . $basename;<br />
				$target_path = &#8216;../bag_thumb/&#8217;;<br />
				$target_path = $target_path . $basename; </p>
<p>				$sqlQuery = &#8220;DELETE FROM &#8221; . $wpdb->prefix . &#8220;bag_thumb WHERE post_id=$postID;&#8221;;<br />
				$wpdb->query($sqlQuery);</p>
<p>				move_uploaded_file($_FILES['bag_thumbnail_photo']['tmp_name'], $target_path);</p>
<p>				// adding record in the database<br />
				$sqlQuery = &#8220;INSERT INTO &#8221; .<br />
				$wpdb->prefix . &#8220;bag_thumb(post_id, image_name)<br />
				VALUES($postID, &#8216;$basename&#8217;)&#8221;;<br />
				$wpdb->query($sqlQuery);<br />
			}</p>
<p>		}</p>
<p>	}</p>
<p>	function isAllowedExtension($fileName)<br />
	{<br />
		$allowedExtensions = array(&#8220;png&#8221;, &#8220;gif&#8221;, &#8220;jpg&#8221;, &#8216;jpeg&#8217;);<br />
		return in_array(end(explode(&#8220;.&#8221;, $fileName)), $allowedExtensions);<br />
	}</p>
<p>	// This starts whenever the plugin is loaded<br />
	add_action(&#8220;plugins_loaded&#8221;, &#8220;init_bag_review_thumb_widget&#8221;);</p>
<p>	// Hook things in, late enough so that add_meta_box() is defined<br />
	if (is_admin())<br />
	{<br />
		/* Use the admin_menu action to define the custom boxes */<br />
		add_action(&#8216;admin_menu&#8217;, &#8216;add_bag_photo_box&#8217;);<br />
	}</p>
<p>	/* Use the save_post action to do something with the data entered */<br />
	add_action(&#8216;save_post&#8217;, &#8216;bag_thumbnail_plugin_save_postdata&#8217;);</p>
<p>?><br />
{/code}</p>
<p>Please notice that I dynamically delete any unnecessary file using the PHP&#8217;s <strong>unlink()</strong> function.</p>
<p><span style="text-decoration: underline;"><strong>Step Three: get your image name from the database</strong></span></p>
<p>I have placed the following code in my <strong>functions.php</strong> file.</p>
<p>{code type=PHP}<br />
<?php</p>
<p>	if(!function_exists('getBagThumbName'))<br />
	{<br />
		function getBagThumbName($postID)<br />
		{<br />
			global $wpdb;<br />
			$sqlQuery = 'SELECT image_name FROM ' . $wpdb->prefix . &#8216;bag_thumb WHERE post_id=&#8217; . $postID . &#8216;;&#8217;;<br />
			$fileName = $wpdb->get_var($sqlQuery);<br />
			$fileName = trim($fileName);<br />
			$fileURL = get_option(&#8216;siteurl&#8217;) . &#8216;/bag_thumb/&#8217; . $fileName;<br />
			if(!empty($fileName))<br />
			{<br />
				return $fileURL;<br />
			}<br />
			else<br />
			{<br />
				return (get_option(&#8216;siteurl&#8217;) . &#8216;/bag_thumb/no_thumb.jpg&#8217;);<br />
			}<br />
		}<br />
	}</p>
<p>?><br />
{/code}</p>
<p><span style="text-decoration: underline;"><strong>Step Four: Link with the index.php or single.php or wherever you want</strong></span></p>
<p>See how I placed the thumbnail image source in the code of <span style="text-decoration: underline;"><strong>index.php</strong></span> and <span style="text-decoration: underline;"><strong>single.php</strong></span> file.</p>
<p>{code type=PHP}</p>
<div id="singlePostAdRight">
		<a href="#postContentAnchor"><img src="<?php<br />
		global $post;<br />
		echo getBagThumbName($post->ID); ?>&#8221; class=&#8221;singlePostThumb&#8221; border=&#8221;0&#8243; /></a>
	</div>
<p>{/code}</p>
<p><span style="text-decoration: underline;"><strong>Step Five: Test</strong></span></p>
<p>Now you need to test and we are done!</p>
<p>You can also download my little plugin if you want from here:<br />
<a title="Wordpress File Upload Plugin" href="http://www.tanzilo.com/demo/code/bag-thumb/bag-thumb.zip" target="_blank">http://www.tanzilo.com/demo/code/bag-thumb/bag-thumb.zip</a></p>
<p>Thank you for reading.</p>
<p><map name='google_ad_map_70_eaab367e2f0158c1'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/70?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_70_eaab367e2f0158c1' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=70&amp;url= http%3A%2F%2Fwww.tanzilo.com%2F2009%2F01%2F15%2Fwordpress-adding-a-custom-option-box-and-developing-file-upload-plugin%2F' /></p>]]></content:encoded>
			<wfw:commentRss>http://www.tanzilo.com/2009/01/15/wordpress-adding-a-custom-option-box-and-developing-file-upload-plugin/feed/</wfw:commentRss>
		<slash:comments>31</slash:comments>
		</item>
		<item>
		<title>WordPress: display posts by category ID. Solution with code &amp; example.</title>
		<link>http://www.tanzilo.com/2009/01/06/wordpress-display-posts-by-category-id-solution-with-code-example/</link>
		<comments>http://www.tanzilo.com/2009/01/06/wordpress-display-posts-by-category-id-solution-with-code-example/#comments</comments>
		<pubDate>Tue, 06 Jan 2009 19:26:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[by category]]></category>
		<category><![CDATA[display]]></category>
		<category><![CDATA[GET]]></category>
		<category><![CDATA[id]]></category>
		<category><![CDATA[posts]]></category>
		<category><![CDATA[show]]></category>

		<guid isPermaLink="false">http://www.tanzilo.com/?p=68</guid>
		<description><![CDATA[Hello Guy! Often in many blogging sites, you will see two or three columns of the most important categories. Recently I had to do this for a blog. It was a little bit cumbersome and time consuming. So, I would like to share the solution so that you can kill the time waste trying yourself [...]]]></description>
			<content:encoded><![CDATA[<p>Hello Guy!</p>
<p>Often in many blogging sites, you will see two or three columns of the most important categories. Recently I had to do this for a blog. It was a little bit cumbersome and time consuming. So, I would like to share the solution so that you can kill the time waste trying yourself in case you do not know how to do it. In this solution, I show 5 posts at maximum from my chosen three categories.</p>
<p>OK.<br />
Let us start and let me show how to do it.</p>
<p><span style="text-decoration: underline;"><strong>Step One: See the sample what would be the output</strong></span></p>
<p><a href="http://www.tanzilo.com/wp-content/uploads/2009/01/posts-by-category-id.jpg" target="_blank"><img class="alignleft size-medium wp-image-69" style="float:none;" title="posts-by-category-id" src="http://www.tanzilo.com/wp-content/uploads/2009/01/posts-by-category-id-300x146.jpg" alt="" width="300" height="146" /></a></p>
<p>In the above image, you will notice that the first category has enough posts, so it can fetch 5 (five) posts for us. But in second column and third column, there are only three posts because those categories do not have more than three posts. And what I want to say at this point is &#8211; although we will try to get 5 posts from each category, we will not get enough in case that category has less than 5 (five) posts and this is done automatically.</p>
<p><span style="text-decoration: underline;"><strong>Step Two: Adding custom function</strong></span></p>
<p>{code type=PHP}<br />
<?php</p>
<p>	if(!function_exists('postListByCategory'))<br />
	{<br />
		function categoryNameByCategoryID($categoryID = 0)<br />
		{<br />
			global $wpdb;<br />
			$sqlQuery = 'SELECT name FROM ' . $wpdb->prefix . &#8220;terms WHERE term_id=$categoryID&#8221;;<br />
			return $wpdb->get_var($sqlQuery);<br />
		}<br />
	}</p>
<p>	if(!function_exists(&#8216;postListByCategory&#8217;))<br />
	{<br />
		function postListByCategoryID($categoryID = 0)<br />
		{<br />
			$outputString = &#8221;;<br />
			query_posts(&#8216;orderby=name&#038;order=asc&#038;cat=&#8217; . $categoryID . &#8216;&#038;showposts=5&#8242;);<br />
			$outputString .= &#8216;
<ul>&#8216; . chr(10);<br />
			while (have_posts()) : the_post();<br />
				$permaLink = get_permalink();<br />
				$permaLink = trim($permaLink);<br />
				if(!empty($permaLink))<br />
				{<br />
					$outputString .= &#8216;
<li>&#8216; . chr(10);<br />
					$outputString .= &#8216;<a href="' . get_permalink() . '">&#8216; . get_the_title($post->ID) . &#8216;</a><br />&#8216; . chr(10);<br />
					$outputString .= &#8216;<small>&#8216; . get_the_time(&#8216;D M jS Y&#8217;) .&#8217;</small>&#8216; . chr(10);<br />
					$outputString .= &#8216;</li>
<p>&#8216; . chr(10);<br />
				}<br />
			endwhile;<br />
			$outputString .= &#8216;</ul>
<p>&#8216; . chr(10);<br />
			return $outputString;<br />
		}<br />
	}</p>
<p>?><br />
{/code}</p>
<p>Now open the <strong>functions.php</strong> file inside your theme directory and insert these two functions. If there is none, create a <strong>functions.php</strong> file. And at this point, please remember that all the functions and coding in this file are automatically added during the code execution.</p>
<p>Note that the function names are self descriptive.</p>
<p><span style="text-decoration: underline;"><strong>Step Three: Embed code in your file(s)</strong></span></p>
<p>Now open your <strong>footer.php</strong> file or any other file and add this code. In 99% cases, you may need to customize this small piece of code. The first three lines are category IDs.</p>
<p>{code type=PHP}<br />
<?php</p>
<p>	$firstColumnCategoryID  = 1;<br />
	$secondColumnCategoryID = 30;<br />
	$thirdColumnCategoryID  = 31;</p>
<p>?>            </p>
<div id="bottomThreeColumns">
<div id="bottomColumn">
<div id="bottomColumnTop">&nbsp;<?php echo categoryNameByCategoryID($firstColumnCategoryID); ?></div>
<p>			<?php echo postListByCategoryID($firstColumnCategoryID); ?>
		</div>
<div id="bottomColumn">
<div id="bottomColumnTop">&nbsp;<?php echo categoryNameByCategoryID($secondColumnCategoryID); ?></div>
<p>				<?php echo postListByCategoryID($secondColumnCategoryID); ?>
		</div>
<div id="bottomColumnThird">
<div id="bottomColumnTop">&nbsp;<?php echo categoryNameByCategoryID($thirdColumnCategoryID); ?></div>
<p>			<?php echo postListByCategoryID($thirdColumnCategoryID); ?>
		</div>
</p></div>
<p>{/code}</p>
<p><span style="text-decoration: underline;"><strong>Step Four: Link your CSS code</strong></span></p>
<p>{code type=CSS}<br />
#bottomThreeColumns<br />
{<br />
	width:940px; min-height:100px; margin:0 auto; clear:both;<br />
}<br />
#bottomThreeColumns UL<br />
{<br />
	margin:0px 0px 30px 0px; padding:0px;<br />
}<br />
#bottomThreeColumns LI<br />
{<br />
	list-style:none; border-bottom:#EEEEEE solid 1px; margin:7px 0px 0px 4px;<br />
}<br />
#bottomThreeColumns LI A<br />
{<br />
	text-decoration:none; color:#000000;<br />
}<br />
#bottomThreeColumns LI A:hover<br />
{<br />
	text-decoration:underline;<br />
}<br />
#bottomThreeColumns SMALL<br />
{<br />
	font-style:italic; line-height:25px; padding:0px 0px 0px 4px;<br />
}<br />
#bottomColumn<br />
{<br />
	float:left; width:300px; margin:20px 20px 0px 0px;<br />
}<br />
#bottomColumnThird<br />
{<br />
	float:left; width:300px; margin:20px 0px 0px 0px;<br />
}<br />
#bottomColumnTop<br />
{<br />
	width:300px; height:26px; background:#5FB8EB; color:#FFFFFF;<br />
	line-height:25px; font-weight:bold;<br />
}<br />
{/code}</p>
<p>I have put the above CSS code in my <strong>style.css</strong> file. In 99% cases, you may need to customize according to your requirements.</p>
<p><span style="text-decoration: underline;"><strong>Step Five: Test everything by opening the link</strong></span></p>
<p>Now test you code and we are done!</p>
<p>Thank you for reading.</p>
<p><map name='google_ad_map_68_eaab367e2f0158c1'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/68?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_68_eaab367e2f0158c1' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=68&amp;url= http%3A%2F%2Fwww.tanzilo.com%2F2009%2F01%2F06%2Fwordpress-display-posts-by-category-id-solution-with-code-example%2F' /></p>]]></content:encoded>
			<wfw:commentRss>http://www.tanzilo.com/2009/01/06/wordpress-display-posts-by-category-id-solution-with-code-example/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>PHP: Serialization &amp; Unserialization explanation, code &amp; example</title>
		<link>http://www.tanzilo.com/2008/12/31/php-serialization-unserialization-explanation-code-example/</link>
		<comments>http://www.tanzilo.com/2008/12/31/php-serialization-unserialization-explanation-code-example/#comments</comments>
		<pubDate>Wed, 31 Dec 2008 13:00:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Example]]></category>
		<category><![CDATA[explanation]]></category>
		<category><![CDATA[Serialization]]></category>
		<category><![CDATA[Unserialization]]></category>

		<guid isPermaLink="false">http://www.tanzilo.com/?p=62</guid>
		<description><![CDATA[Hello Folks! When I was new to PHP 5 Object Oriented Programming (OOP), the serialization and un-serialization issues were not clear to me and I used to get confused with them often. Nowadays I can play with them easily and I will try to share my knowledge with you so that you can kill your [...]]]></description>
			<content:encoded><![CDATA[<p>Hello Folks!</p>
<p>When I was new to PHP 5 Object Oriented Programming (OOP), the serialization and un-serialization issues were not clear to me and I used to get confused with them often. Nowadays I can play with them easily and I will try to share my knowledge with you so that you can kill your confusion on these topics.</p>
<p>OK. Let us start!</p>
<p><span style="text-decoration: underline;"><strong>What is Serialization?</strong></span></p>
<p>This process makes a storable representation of a value that is useful for storing or passing PHP values around without losing their type and structure.</p>
<p><span style="text-decoration: underline;"><strong>Remember the &#8220;__sleep&#8221; function in case of Serialization</strong></span></p>
<p>Before starting your serialization process, PHP will execute the <strong>__sleep</strong> function automatically. This is a magic function or method.</p>
<p><span style="text-decoration: underline;"><strong>What is Unserialization?</strong></span></p>
<p>This process takes a single serialized variable and converts it back into a PHP value.</p>
<p><span style="text-decoration: underline;"><strong>Remember the &#8220;__wakeup&#8221; function in case of Unserialization</strong></span></p>
<p>Before starting your unserialization process, PHP will execute the <strong>__wakeup</strong> function automatically. This is a magic function or method.</p>
<p><span style="text-decoration: underline;"><strong>What can you Serialize and Unserialize?</strong></span></p>
<p>Many things as such</p>
<ol>
<li>Variables (Integer, Float, Real, String etc.)</li>
<li>Arrays</li>
<li>Objects etc.</li>
</ol>
<p><span style="text-decoration: underline;"><strong>What cannot you Serialize and Unserialize?</strong></span></p>
<p>Only one type</p>
<ol>
<li>Resource-type</li>
</ol>
<p><span style="text-decoration: underline;"><strong>A simple example of Serialization and Unserialization</strong></span></p>
<p>{code type=PHP}<br />
<?php</p>
<p>	require_once "class.serialize.php";<br />
	$myObject = new SerializationTest();<br />
	$myObject->counter = 999;<br />
	$myObject->myName  = &#8216;Random Visitor&#8217;;<br />
	$myObject->myAge   = 59;</p>
<p>	$myString = &#8216;I am a simple line.&#8217;;<br />
	$myArray = array();<br />
	$myArray[0] = &#8216;One&#8217;;<br />
	$myArray[1] = &#8216;Two&#8217;;<br />
	$myArray[2] = &#8216;Three&#8217;;</p>
<p>	echo $myString . &#8216;<br />&#8216;;<br />
	var_dump($myArray);<br />
	echo &#8216;<br />&#8216;;<br />
	echo &#8216;$myObject->counter: &#8216; . $myObject->counter . &#8216;<br />&#8216;;<br />
	echo &#8216;$myObject->myName: &#8216; . $myObject->myName . &#8216;<br />&#8216;;<br />
	echo &#8216;$myObject->myAge: &#8216; . $myObject->myAge . &#8216;<br />&#8216;;<br />
	var_dump($myObject);</p>
<p>	$mySerializedString = serialize($myString);<br />
	$mySerializedArray = serialize($myArray);<br />
	$mySerializedObject = serialize($myObject);</p>
<p>	$myString = &#8216;I have changed!&#8217;;<br />
	$myArray[0] = &#8216;New 1&#8242;;<br />
	$myArray[1] = &#8216;New 2&#8242;;<br />
	$myArray[2] = &#8216;New 3&#8242;;</p>
<p>	echo &#8216;</p>
<p>&#8216;;<br />
	echo $myString . &#8216;<br />&#8216;;<br />
	var_dump($myArray);<br />
	echo &#8216;<br />&#8216;;</p>
<p>	$myUnserializedString = unserialize($mySerializedString);<br />
	$myUnserializedArray = unserialize($mySerializedArray);<br />
	$myUnserializedObject = unserialize($mySerializedObject);</p>
<p>	echo &#8216;</p>
<p>&#8216;;<br />
	echo $myUnserializedString . &#8216;<br />&#8216;;<br />
	var_dump($myUnserializedArray);<br />
	echo &#8216;<br />&#8216;;<br />
	echo &#8216;$myUnserializedObject->counter: &#8216; . $myUnserializedObject->counter . &#8216;<br />&#8216;;<br />
	echo &#8216;$myUnserializedObject->myName: &#8216; . $myUnserializedObject->myName . &#8216;<br />&#8216;;<br />
	echo &#8216;$myUnserializedObject->myAge: &#8216; . $myUnserializedObject->myAge . &#8216;<br />&#8216;;<br />
	var_dump($myUnserializedObject);</p>
<p>?><br />
{/code}</p>
<p>And here is the related class:</p>
<p>{code type=PHP}<br />
<?php</p>
<p>	class SerializationTest<br />
	{<br />
		public $counter;<br />
		public $myName;<br />
		public $myAge;<br />
		function __construct()<br />
		{<br />
			$this->counter = 100;<br />
			$this->myName  = &#8216;Tanzilo Insido&#8217;;<br />
			$this->myAge   = 28;<br />
		}</p>
<p>		function __sleep()<br />
		{<br />
			echo &#8220;<br />
<h3>__sleep()</h3>
<p>&#8220;;<br />
			$this->counter = $this->counter + 1;<br />
			echo &#8216;Serialization Process Started!&#8217; . &#8216;<br />&#8216;;<br />
			echo &#8216;$this->counter: &#8216; . $this->counter .  &#8216;<br />&#8216;;<br />
			return array(myString);<br />
		}</p>
<p>		function __wakeup()<br />
		{<br />
			echo &#8220;<br />
<h3>__wakeup()</h3>
<p>&#8220;;<br />
			$this->counter = $this->counter &#8211; 1;<br />
			echo &#8216;UnSerialization Process Started!&#8217; . &#8216;<br />&#8216;;<br />
			echo &#8216;$this->counter: &#8216; . $this->counter .  &#8216;<br />&#8216;;<br />
		}</p>
<p>	}</p>
<p>?><br />
{/code}</p>
<p><span style="text-decoration: underline;"><strong>Explanation of the example</strong></span></p>
<p>If you notice the A to Z of the above code, you will find that we have a <strong>$myString</strong> variable, <strong>$myArray</strong> array and <strong>$myObject</strong> object. First of all, we have set values to them and then printed them all. They all perform as expected. Then we change all the values. Next when we serialize and unserialize the values, our original dara structure returns! And that is what we wanted.</p>
<p>Here is the result of the above code:</p>
<p><a href="http://www.tanzilo.com/wp-content/uploads/2008/12/serialize_1.jpg"><img class="alignleft size-full wp-image-65" title="serialize_1" src="http://www.tanzilo.com/wp-content/uploads/2008/12/serialize_1.jpg" alt="" width="500" height="337" style="float:none;" /></a></p>
<p><span style="text-decoration: underline;"><strong>An interesting thing to note:</strong></span><br />
I would like to draw your attention to the fact that using <strong>__sleep()</strong> method, you can change the values of your declared and initialized variables. But you cannot change them by using <strong>__wakeup()</strong> function. For example, see the following code:</p>
<p>Now we serialize 3 (three)  times and unserialize 2 (two) times.</p>
<p>{code type=PHP}<br />
<?php</p>
<p>	require_once "class.serialize.php";<br />
	$myObject = new SerializationTest();</p>
<p>	echo '<br />
<h3>Start Value:</h3>
<p>&#8216;;<br />
	echo &#8216;$this->counter: &#8216; . $myObject->counter . &#8216;<br />&#8216;;<br />
	echo &#8216;$this->myString: &#8216; . $myObject->myString;</p>
<p>	$serializeData_1 = serialize($myObject);<br />
	$serializeData_2 = serialize($myObject);<br />
	$serializeData_3 = serialize($myObject);</p>
<p>	$unSerializeData_1 = unserialize($serializeData_1);<br />
	$unSerializeData_2 = unserialize($serializeData_2);</p>
<p>?><br />
{/code}</p>
<p>And here is the result if we serialize 3 (three)  times and unserialize 2 (two) times.</p>
<p><a href="http://www.tanzilo.com/wp-content/uploads/2008/12/serialize_2.jpg"><img class="alignleft size-full wp-image-66" title="serialize_2" src="http://www.tanzilo.com/wp-content/uploads/2008/12/serialize_2.jpg" alt="" width="236" height="591" style="float:none;" /></a></p>
<p>Although we initialized <strong>$this-&gt;counter</strong> variable in the <strong>__construct()</strong> function, it is not used or has no effect in <strong>__wakeup()</strong> function. But it works properly in <strong>__sleep()</strong> or <strong>serialize()</strong> process. But what is the reason? The explanation is simple. The <strong>__wakeup()</strong> is part of the process when your data is retrieved from memory. Another thing is &#8211; did you notice the array return in the <strong>__sleep()</strong> function? Without returning this, the process often does not work. So, please remember to keep in your code.</p>
<p><span style="text-decoration: underline;">You can download these small pieces of code files from here:</span><br />
<a title="PHP Serialize and Unserialize" href="http://www.tanzilo.com/demo/code/serialize/serialize.zip" target="_blank">http://www.tanzilo.com/demo/code/serialize/serialize.zip</a></p>
<p>Thank you for reading.</p>
<p><map name='google_ad_map_62_eaab367e2f0158c1'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/62?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_62_eaab367e2f0158c1' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=62&amp;url= http%3A%2F%2Fwww.tanzilo.com%2F2008%2F12%2F31%2Fphp-serialization-unserialization-explanation-code-example%2F' /></p>]]></content:encoded>
			<wfw:commentRss>http://www.tanzilo.com/2008/12/31/php-serialization-unserialization-explanation-code-example/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>PHP &amp; MySQL: Creating a website in your local language smoothly</title>
		<link>http://www.tanzilo.com/2008/12/29/php-mysql-creating-a-website-in-your-local-language-smoothly/</link>
		<comments>http://www.tanzilo.com/2008/12/29/php-mysql-creating-a-website-in-your-local-language-smoothly/#comments</comments>
		<pubDate>Mon, 29 Dec 2008 12:04:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Afrikaans]]></category>
		<category><![CDATA[Albanian]]></category>
		<category><![CDATA[Amharic]]></category>
		<category><![CDATA[Arabic]]></category>
		<category><![CDATA[Armenian]]></category>
		<category><![CDATA[Assamese]]></category>
		<category><![CDATA[Aymara]]></category>
		<category><![CDATA[Azeri]]></category>
		<category><![CDATA[Belarusian]]></category>
		<category><![CDATA[Bengali]]></category>
		<category><![CDATA[Bislama]]></category>
		<category><![CDATA[Bosnian]]></category>
		<category><![CDATA[Bulgarian]]></category>
		<category><![CDATA[Burmese]]></category>
		<category><![CDATA[Catalan]]></category>
		<category><![CDATA[Chinese]]></category>
		<category><![CDATA[Creating]]></category>
		<category><![CDATA[Croatian]]></category>
		<category><![CDATA[Czech]]></category>
		<category><![CDATA[Danish]]></category>
		<category><![CDATA[Dari]]></category>
		<category><![CDATA[Develop]]></category>
		<category><![CDATA[Dhivehi]]></category>
		<category><![CDATA[Dutch]]></category>
		<category><![CDATA[Dzongkha]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[Esperanto]]></category>
		<category><![CDATA[Estonian]]></category>
		<category><![CDATA[Fijian]]></category>
		<category><![CDATA[Filipino]]></category>
		<category><![CDATA[Finnish]]></category>
		<category><![CDATA[French]]></category>
		<category><![CDATA[Frisian]]></category>
		<category><![CDATA[Gagauz]]></category>
		<category><![CDATA[Georgian]]></category>
		<category><![CDATA[German]]></category>
		<category><![CDATA[Greek]]></category>
		<category><![CDATA[Guaraní]]></category>
		<category><![CDATA[Gujarati]]></category>
		<category><![CDATA[Haitian Creole]]></category>
		<category><![CDATA[Hebrew]]></category>
		<category><![CDATA[Hindi]]></category>
		<category><![CDATA[Hiri Motu]]></category>
		<category><![CDATA[Hungarian]]></category>
		<category><![CDATA[Icelandic]]></category>
		<category><![CDATA[Indonesian]]></category>
		<category><![CDATA[Italian]]></category>
		<category><![CDATA[Japanese]]></category>
		<category><![CDATA[Kannada]]></category>
		<category><![CDATA[Kashmiri]]></category>
		<category><![CDATA[Kazakh]]></category>
		<category><![CDATA[Khmer]]></category>
		<category><![CDATA[Korean]]></category>
		<category><![CDATA[Kurdish]]></category>
		<category><![CDATA[Kyrgyz]]></category>
		<category><![CDATA[Lao]]></category>
		<category><![CDATA[Latvian]]></category>
		<category><![CDATA[Lithuanian]]></category>
		<category><![CDATA[local language]]></category>
		<category><![CDATA[Luxembourgish]]></category>
		<category><![CDATA[Macedonian]]></category>
		<category><![CDATA[Malagasy]]></category>
		<category><![CDATA[Malay]]></category>
		<category><![CDATA[Malayalam]]></category>
		<category><![CDATA[Maltese]]></category>
		<category><![CDATA[Mandarin]]></category>
		<category><![CDATA[Māori]]></category>
		<category><![CDATA[Marathi]]></category>
		<category><![CDATA[Mayan]]></category>
		<category><![CDATA[Moldovan]]></category>
		<category><![CDATA[Mongolian]]></category>
		<category><![CDATA[Montenegrin]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Náhuatl]]></category>
		<category><![CDATA[Ndebele]]></category>
		<category><![CDATA[Nepali]]></category>
		<category><![CDATA[New Zealand Sign Language]]></category>
		<category><![CDATA[Northern Sotho]]></category>
		<category><![CDATA[Norwegian]]></category>
		<category><![CDATA[Oriya]]></category>
		<category><![CDATA[Papiamento]]></category>
		<category><![CDATA[Pashto]]></category>
		<category><![CDATA[Persian]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Polish]]></category>
		<category><![CDATA[Portuguese]]></category>
		<category><![CDATA[Punjabi]]></category>
		<category><![CDATA[Quechua]]></category>
		<category><![CDATA[Rhaeto-Romansh]]></category>
		<category><![CDATA[Romanian]]></category>
		<category><![CDATA[Russian]]></category>
		<category><![CDATA[Sanskrit]]></category>
		<category><![CDATA[Serbian]]></category>
		<category><![CDATA[Shona]]></category>
		<category><![CDATA[Sindhi]]></category>
		<category><![CDATA[Sinhala]]></category>
		<category><![CDATA[Slovak]]></category>
		<category><![CDATA[Slovene]]></category>
		<category><![CDATA[Somali]]></category>
		<category><![CDATA[Sotho]]></category>
		<category><![CDATA[Spanish]]></category>
		<category><![CDATA[Swahili]]></category>
		<category><![CDATA[Swati]]></category>
		<category><![CDATA[Swedish]]></category>
		<category><![CDATA[Tagalog]]></category>
		<category><![CDATA[Tajik]]></category>
		<category><![CDATA[Tamil]]></category>
		<category><![CDATA[Telugu]]></category>
		<category><![CDATA[Tetum]]></category>
		<category><![CDATA[Thai]]></category>
		<category><![CDATA[Tok Pisin]]></category>
		<category><![CDATA[Tsonga]]></category>
		<category><![CDATA[Tswana]]></category>
		<category><![CDATA[Turkish]]></category>
		<category><![CDATA[Turkmen]]></category>
		<category><![CDATA[Ukrainian]]></category>
		<category><![CDATA[Urdu]]></category>
		<category><![CDATA[Uzbek]]></category>
		<category><![CDATA[Venda]]></category>
		<category><![CDATA[Vietnamese]]></category>
		<category><![CDATA[website]]></category>
		<category><![CDATA[Welsh]]></category>
		<category><![CDATA[Xhosa]]></category>
		<category><![CDATA[Yiddish]]></category>
		<category><![CDATA[Zulu]]></category>

		<guid isPermaLink="false">http://www.tanzilo.com/?p=63</guid>
		<description><![CDATA[Hello Developer, You know English is the international language and accepted as international communication. So, most of the websites have been developed in English. But in many other times, a developer needs to work with local languages where they are developing a website in PHP. If you develop in local language, you need to know [...]]]></description>
			<content:encoded><![CDATA[<p>Hello Developer,</p>
<p>You know English is the international language and accepted as international communication. So, most of the websites have been developed in English. But in many other times, a developer needs to work with local languages where they are developing a website in PHP. If you develop in local language, you need to know a small trick and that will show your content properly in all browsers smoothly.</p>
<p>So, what is the technique?</p>
<p>Well. Let me explain step by step.</p>
<p><span style="text-decoration: underline;"><strong>Step One: An observation</strong></span><br />
I will show you the source code of two Bengali newspaper. In this newspaper: <a title="Prothom Alo" href="http://www.prothom-alo.com/" target="_blank">http://www.prothom-alo.com</a>, the fonts and text comes properly in all browsers. But in this newspaper: <a title="Ittefaq" href="http://www.ittefaq.com" target="_blank">http://www.ittefaq.com</a>, it can show text and fonts properly only in Internet Explorer.</p>
<p>Now the matter is we must make sure our content will be displayed properly in any browser. Right?</p>
<p>OK. So what is the difference between the two websites I just gave example?</p>
<p>If you take a look at the source code of the first website&#8217;s content, you will find it is like this:<span style="text-decoration: underline;">&amp;<span class="entity">#2488;</span>&amp;<span class="entity">#2691;</span>&amp;<span class="entity">#2474;</span>&amp;<span class="entity">#2494;</span>&amp;<span class="entity">#2470;</span>&amp;<span class="entity">#2453;</span></span></p>
<p>This is another website that had been developed as smooth site in the same technique: <a title="bdnews 24" href="http://www.bdnews24.com/bangla" target="_blank">http://www.bdnews24.com/bangla</a>. If you check its code, you will see that it uses same type of code for its text.</p>
<p>So, what are these <span style="text-decoration: underline;">&amp;<span class="entity">#2474;</span>&amp;<span class="entity">#2494;</span>&amp;<span class="entity">#2470;</span>&amp;<span class="entity">#2453;</span>&amp;<span class="entity">#2496;</span>&amp;</span><span class="entity"><span style="text-decoration: underline;">#2527;</span> things? It is very interesting that these are universal representation of local language in HTML entities. For every character of any local language, there is a unique and fixed symbol defined such as </span><span style="text-decoration: underline;">&amp;<span class="entity">#2474;</span></span><span class="entity"> in HTML entities</span><span class="entity">. When you bring this kind of text in your browser source code, the site content looks smooth without any break and fonts displays properly.</span></p>
<p>Now if you open the source code of <a title="Ittefaq" href="http://www.ittefaq.com" target="_blank">http://www.ittefaq.com</a>, you will see something like <span style="text-decoration: underline;">AvR beg RvZxq msm` wbe©vP‡b jovB n‡e †RvU-gnv‡Rv‡Ui g‡a¨</span>. The matter is they are also showing Bengali news content, but in a different way that is not useful in cross-broswer platform. This is often totally recognized by only Internet Explorer and often partially recognized by other browsers.</p>
<p><span style="text-decoration: underline;"><strong>Step Two: Storing your local language content in the database</strong></span><br />
You see I have some content in my local language (Bangla) in the database.</p>
<p><a href="http://www.tanzilo.com/wp-content/uploads/2008/12/bangla_news_content.jpg"><img class="alignleft size-full wp-image-64" style="float:none;" title="bangla_news_content" src="http://www.tanzilo.com/wp-content/uploads/2008/12/bangla_news_content.jpg" alt="" width="500" height="174" /></a></p>
<p><span style="text-decoration: underline;"><strong>Step Three: Converting your local language text in Universal code</strong></span><br />
Well. This is extremely easy.</p>
<p>{code type=PHP}<br />
<?php</p>
<p>	class UnicodeHandler<br />
	{<br />
		var $dbLink;<br />
		var $sqlQuery;<br />
		var $dbResult;<br />
		var $dbRow;<br />
		var $salary;<br />
		var $bonus;</p>
<p>		/* Use this constructor in case your PHP version is 4. */<br />
/*<br />
		function UnicodeHandler()<br />
		{<br />
			$this->dbLink = &#8221;;<br />
			$this->sqlQuery = &#8221;;<br />
			$this->dbResult = &#8221;;<br />
			$this->dbRow = &#8221;;<br />
			$this->mySalary = 0;<br />
			$this->myBonus = 0;</p>
<p>			$this->dbLink = mysql_connect(&#8216;localhost&#8217;, &#8216;root&#8217;, &#8221;);<br />
			mysql_query(&#8220;SET character_set_results=utf8&#8243;, $this->dbLink);<br />
			mb_language(&#8216;uni&#8217;);<br />
			mb_internal_encoding(&#8216;UTF-8&#8242;);</p>
<p>			mysql_select_db(&#8216;test&#8217;, $this->dbLink);<br />
			mysql_query(&#8220;set names &#8216;utf8&#8242;&#8221;,$this->dbLink);<br />
		}<br />
*/</p>
<p>		/* Use this constructor in case your PHP version is 5 or 5+. */<br />
		/* I assume you are using PHP 5 or 5+. */<br />
		function __construct()<br />
		{<br />
			$this->dbLink = &#8221;;<br />
			$this->sqlQuery = &#8221;;<br />
			$this->dbResult = &#8221;;<br />
			$this->dbRow = &#8221;;<br />
			$this->mySalary = 0;<br />
			$this->myBonus = 0;</p>
<p>			$this->dbLink = mysql_connect(&#8216;localhost&#8217;, &#8216;root&#8217;, &#8221;);<br />
			mysql_query(&#8220;SET character_set_results=utf8&#8243;, $this->dbLink);<br />
			mb_language(&#8216;uni&#8217;);<br />
			mb_internal_encoding(&#8216;UTF-8&#8242;);</p>
<p>			mysql_select_db(&#8216;test&#8217;, $this->dbLink);<br />
			mysql_query(&#8220;set names &#8216;utf8&#8242;&#8221;,$this->dbLink);<br />
		}</p>
<p>		function displayLocalContent()<br />
		{<br />
			mysql_query(&#8220;SET character_set_results=utf8&#8243;, $this->dbLink);<br />
			$this->sqlQuery = &#8220;SELECT * FROM unitext &#8220;;<br />
			$this->dbResult = mysql_query($this->sqlQuery, $this->dbLink);<br />
			while($this->dbRow = mysql_fetch_object($this->dbResult))<br />
			{<br />
				echo &#8216;News: &#8216; . $this->convertToLocalHtml($this->dbRow->news) . &#8216;<br />&#8216;;<br />
			}</p>
<p>		}</p>
<p>		function convertToLocalHtml($localHtmlEquivalent)<br />
		{</p>
<p>			$localHtmlEquivalent = mb_convert_encoding($localHtmlEquivalent,&#8221;HTML-ENTITIES&#8221;,&#8221;UTF-8&#8243;);<br />
			return $localHtmlEquivalent;<br />
		}<br />
	}</p>
<p>?><br />
{/code}</p>
<p>The <span style="text-decoration: underline;">displayLocalContent()</span> function is going to display the news and <span style="text-decoration: underline;">convertToLocalHtml()</span> function converts my utf-8 content to HTML entities.</p>
<p>And here in <strong>index.php</strong> I am executing my <span style="text-decoration: underline;">displayLocalContent()</span> function.</p>
<p>{code type=PHP}<br />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><br />
<html xmlns="http://www.w3.org/1999/xhtml"><br />
<head><br />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></p>
<p></head></p>
<p><body><br />
<?php</p>
<p>	include_once 'class.unicode.php';<br />
	$unicodeObject = new UnicodeHandler();<br />
	$unicodeObject->displayLocalContent();</p>
<p>?><br />
</body><br />
</html><br />
{/code}</p>
<p>As a result, the output is now as <span style="text-decoration: underline;">ঢাকা, ডিসে</span> etc.</p>
<p><span style="text-decoration: underline;"><strong>Step Four: You need to check my other posting for SELECT, INSERT &amp; UPDATE your local language.</strong></span><br />
Here goes my other article so that you can perform all required operations for storing and displaying information in browser smoothly:<br />
<a title="Php mysql unicode solution to chinese russian or any language" href="http://www.tanzilo.com/2008/10/13/php-mysql-unicode-solution-to-chinese-russian-or-any-language/" target="_blank">http://www.tanzilo.com/2008/10/13/php-mysql-unicode-solution-to-chinese-russian-or-any-language/</a></p>
<p><span style="text-decoration: underline;"><strong>An alternative way</strong></span><br />
I have an alternative way in my mind and that is when you store the data in the database, you can first convert them to universal code such as <span style="text-decoration: underline;">&amp;<span class="entity">#2453;</span>&amp;<span class="entity">#2496;</span>&amp;</span><span class="entity"><span style="text-decoration: underline;">#2527;</span></span>and then directly show your text.</p>
<p><strong>This article will cover any language such as</strong> Afrikaans, Albanian, Amharic, Arabic, Armenian, Assamese, Aymara, Azeri, Belarusian, Bengali, Bislama, Bosnian, Bulgarian, Burmese, Catalan, Chinese, Mandarin,Croatian, Czech, Danish, Dari, Dhivehi, Dutch, Dzongkha, English, Esperanto, Estonian, Fijian, Filipino, Finnish, French, Frisian,  Gagauz, Georgian, German, Greek, Guaraní, Gujarati, Haitian Creole, Hebrew, Hindi, Hiri Motu, Hungarian, Icelandic, Indonesian, Italian, Japanese, Kannada, Kashmiri, Kazakh, Khmer, Korean, Kurdish, Kyrgyz, Lao, Latvian, Lithuanian, Luxembourgish, Macedonian, Malagasy, Malay, Malayalam, Maltese, Māori, Marathi, Mayan, Moldovan, Mongolian, Montenegrin,Náhuatl, Ndebele, Nepali, New Zealand Sign Language, Northern Sotho, Norwegian, Oriya, Papiamento, Pashto, Persian, Polish, Portuguese, Punjabi, Quechua, Romanian, Rhaeto-Romansh, Russian, Sanskrit, Serbian, Shona, Sindhi, Sinhala, Slovak, Slovene, Somali, Sotho, Spanish, Swahili, Swati, Swedish, Tagalog, Tajik, Tamil, Telugu, Tetum, Thai, Tok Pisin, Tsonga, Tswana, Turkish, Turkmen, Ukrainian, Urdu, Uzbek, Venda, Vietnamese, Welsh, Xhosa, Yiddish, Zulu etc.</p>
<p>You can also download this small piece of code from here:<br />
<a title="convert to unicode" href="http://www.tanzilo.com/demo/code/convert_to_unicode/convert_to_unicode.zip" target="_blank">http://www.tanzilo.com/demo/code/convert_to_unicode/convert_to_unicode.zip</a></p>
<p>Thank you for reading.</p>
<p><map name='google_ad_map_63_eaab367e2f0158c1'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/63?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_63_eaab367e2f0158c1' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=63&amp;url= http%3A%2F%2Fwww.tanzilo.com%2F2008%2F12%2F29%2Fphp-mysql-creating-a-website-in-your-local-language-smoothly%2F' /></p>]]></content:encoded>
			<wfw:commentRss>http://www.tanzilo.com/2008/12/29/php-mysql-creating-a-website-in-your-local-language-smoothly/feed/</wfw:commentRss>
		<slash:comments>40</slash:comments>
		</item>
		<item>
		<title>PHP &amp; MySQL: Unicode number add, subtract etc for any language</title>
		<link>http://www.tanzilo.com/2008/12/23/php-mysql-unicode-number-add-subtract-etc-for-any-language/</link>
		<comments>http://www.tanzilo.com/2008/12/23/php-mysql-unicode-number-add-subtract-etc-for-any-language/#comments</comments>
		<pubDate>Tue, 23 Dec 2008 18:22:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[add]]></category>
		<category><![CDATA[any language]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[divide]]></category>
		<category><![CDATA[Example]]></category>
		<category><![CDATA[multiply]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[number]]></category>
		<category><![CDATA[solution]]></category>
		<category><![CDATA[subtract]]></category>
		<category><![CDATA[Unicode]]></category>

		<guid isPermaLink="false">http://www.tanzilo.com/?p=60</guid>
		<description><![CDATA[Hello Coders! Recently a visitor from my country asked me how he can add Unicode numbers stored in MySQL database.  I was thinking that it is really a good question. Because you may store any number in any local language to your database and later you may try to add or delete them. For example, [...]]]></description>
			<content:encoded><![CDATA[<p>Hello Coders!</p>
<p>Recently a visitor from my country asked me how he can add Unicode numbers stored in MySQL database.  I was thinking that it is really a good question. Because you may store any number in any local language to your database and later you may try to add or delete them.</p>
<p>For example, in Bangla language an employee&#8217;s salary can be <span style="text-decoration: underline;"><strong><span class="Apple-style-span" style="border-collapse: separate; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-family: 'Times New Roman'; color: #000000;">২৪</span><span class="Apple-style-span" style="border-collapse: separate; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-family: 'Times New Roman'; color: #000000;">১৮৬</span></strong></span> (which is 24186 in English) bucks and the coder may want to store it in a table under <span style="text-decoration: underline;">salary</span> field. Another field can be bonus and it can be <span style="text-decoration: underline;"><strong><span class="Apple-style-span" style="border-collapse: separate; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-family: 'Times New Roman'; color: #000000;">২০০</span></strong></span><span style="text-decoration: underline;"><strong><span class="Apple-style-span" style="border-collapse: separate; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-family: 'Times New Roman'; color: #000000;">০</span></strong></span> (2000 in English). Now the coder may want to add them up anytime required. You know adding 24186 and 2000 is easy. But what the coder may do in case the values are stored in a local language?</p>
<p>The visitor asked me how he can use the MySQL <strong>sum()</strong> function in case the data are stored in Unicode format. Well. I do not think MySQL&#8217;s unicode will support the <strong>sum()</strong> function or even if there is one I do not know frankly speaking. So, I thought and developed an alternative solution.</p>
<p>Here is the alternative solution steps:</p>
<ol>
<li>I get the unicode numbers from the database</li>
<li>Convert them to English number</li>
<li>Sum them up or anything like substract, multiply or divide etc</li>
<li>Convert the result to Unicode once again</li>
</ol>
<p>Thus, it looks simple procedure. Right?</p>
<p><span style="color: #800000;"><strong>Before we start I would like to suggest you download the codes from the bottom link of the page and take a look. Because some code may not look as the original one for browser&#8217;s case sensitiveness. So, it is better to look at the original code from the download link below.</strong></span></p>
<p>So,  I wrote a small class to handle the whole procedure and here goes the coding of my class:</p>
<p>{code type=PHP}<br />
<?php</p>
<p>	class UnicodeHandler<br />
	{<br />
		var $dbLink;<br />
		var $sqlQuery;<br />
		var $dbResult;<br />
		var $dbRow;<br />
		var $salary;<br />
		var $bonus;</p>
<p>		/* Use this constructor in case your PHP version is 4. */<br />
		/*<br />
		function UnicodeHandler()<br />
		{<br />
			$this->dbLink = &#8221;;<br />
			$this->sqlQuery = &#8221;;<br />
			$this->dbResult = &#8221;;<br />
			$this->dbRow = &#8221;;<br />
			$this->mySalary = 0;<br />
			$this->myBonus = 0;</p>
<p>			$this->dbLink = mysql_connect(&#8216;localhost&#8217;, &#8216;root&#8217;, &#8221;);<br />
			mysql_query(&#8220;SET character_set_results=utf8&#8243;, $this->dbLink);<br />
			mb_language(&#8216;uni&#8217;);<br />
			mb_internal_encoding(&#8216;UTF-8&#8242;);</p>
<p>			mysql_select_db(&#8216;test&#8217;, $this->dbLink);<br />
			mysql_query(&#8220;set names &#8216;utf8&#8242;&#8221;,$this->dbLink);<br />
		}<br />
		*/</p>
<p>		/* Use this constructor in case your PHP version is 5 or 5+. */<br />
		/* I assume you are using PHP 5 or 5+. */<br />
		function __construct()<br />
		{<br />
			$this->dbLink = &#8221;;<br />
			$this->sqlQuery = &#8221;;<br />
			$this->dbResult = &#8221;;<br />
			$this->dbRow = &#8221;;<br />
			$this->mySalary = 0;<br />
			$this->myBonus = 0;</p>
<p>			$this->dbLink = mysql_connect(&#8216;localhost&#8217;, &#8216;root&#8217;, &#8221;);<br />
			mysql_query(&#8220;SET character_set_results=utf8&#8243;, $this->dbLink);<br />
			mb_language(&#8216;uni&#8217;);<br />
			mb_internal_encoding(&#8216;UTF-8&#8242;);</p>
<p>			mysql_select_db(&#8216;test&#8217;, $this->dbLink);<br />
			mysql_query(&#8220;set names &#8216;utf8&#8242;&#8221;,$this->dbLink);<br />
		}</p>
<p>		function displayTotalPayment()<br />
		{<br />
			mysql_query(&#8220;SET character_set_results=utf8&#8243;, $this->dbLink);<br />
			$this->sqlQuery = &#8220;SELECT * FROM bangla_number &#8220;;<br />
			$this->dbResult = mysql_query($this->sqlQuery, $this->dbLink);<br />
			$this->total = 0;<br />
			while($this->dbRow = mysql_fetch_object($this->dbResult))<br />
			{<br />
				echo &#8216;Employee ID # &#8216; . $this->dbRow->id . &#8216;<br />&#8216;;<br />
				echo &#8216;Salary: &#8216; . $this->dbRow->salary . &#8216;<br />&#8216;;<br />
				echo &#8216;Bonus: &#8216; . $this->dbRow->bonus . &#8216;<br />&#8216;;<br />
				$totalPayment = $this->convertToEnglishNumber($this->dbRow->salary) +<br />
				$this->convertToEnglishNumber($this->dbRow->bonus);<br />
				echo &#8216;Total Payment: &#8216; . $this->convertToBanglaNumber($totalPayment) . &#8216;<br />&#8216;;<br />
				echo &#8216;</p>
<p>&#8216;;<br />
			}</p>
<p>		}</p>
<p>		function convertToEnglishNumber($unicodeNumber)<br />
		{</p>
<p>			$englishNumber = mb_convert_encoding($unicodeNumber,&#8221;HTML-ENTITIES&#8221;,&#8221;UTF-8&#8243;);<br />
			$englishNumber = str_replace(&#8216;&#2534;&#8217;, &#8217;0&#8242;, $englishNumber);<br />
			$englishNumber = str_replace(&#8216;&#2535;&#8217;, &#8217;1&#8242;, $englishNumber);<br />
			$englishNumber = str_replace(&#8216;&#2536;&#8217;, &#8217;2&#8242;, $englishNumber);<br />
			$englishNumber = str_replace(&#8216;&#2537;&#8217;, &#8217;3&#8242;, $englishNumber);<br />
			$englishNumber = str_replace(&#8216;&#2538;&#8217;, &#8217;4&#8242;, $englishNumber);<br />
			$englishNumber = str_replace(&#8216;&#2539;&#8217;, &#8217;5&#8242;, $englishNumber);<br />
			$englishNumber = str_replace(&#8216;&#2540;&#8217;, &#8217;6&#8242;, $englishNumber);<br />
			$englishNumber = str_replace(&#8216;&#2541;&#8217;, &#8217;7&#8242;, $englishNumber);<br />
			$englishNumber = str_replace(&#8216;&#2542;&#8217;, &#8217;8&#8242;, $englishNumber);<br />
			$englishNumber = str_replace(&#8216;&#2543;&#8217;, &#8217;9&#8242;, $englishNumber);<br />
			return $englishNumber;<br />
		}</p>
<p>		function convertToBanglaNumber($englishNumber)<br />
		{<br />
			$englishNumber = (string) $englishNumber;<br />
			$banglaNumber = &#8221;;<br />
			$indexLimit = strlen($englishNumber);<br />
			for($i=0; $i<$indexLimit; $i++)<br />
			{<br />
				switch($englishNumber[$i])<br />
				{<br />
					case "0":<br />
						$banglaNumber .= '&#2534;';<br />
						break;<br />
					case "1":<br />
						$banglaNumber .= '&#2535;';<br />
						break;<br />
					case "2":<br />
						$banglaNumber .= '&#2536;';<br />
						break;<br />
					case "3":<br />
						$banglaNumber .= '&#2537;';<br />
						break;<br />
					case "4":<br />
						$banglaNumber .= '&#2538;';<br />
						break;<br />
					case "5":<br />
						$banglaNumber .= '&#2539;';<br />
						break;<br />
					case "6":<br />
						$banglaNumber .= '&#2540;';<br />
						break;<br />
					case "7":<br />
						$banglaNumber .= '&#2541;';<br />
						break;<br />
					case "8":<br />
						$banglaNumber .= '&#2542;';<br />
						break;<br />
					case "9":<br />
						$banglaNumber .= '&#2543;';<br />
						break;<br />
					default:<br />
						$banglaNumber .= $englishNumber[$i];<br />
						break;<br />
				}<br />
			}<br />
			return $banglaNumber;<br />
		}</p>
<p>	}</p>
<p>?><br />
{/code}</p>
<p>If you are not using Bengali language, you need to configure the equivalent number values in <span style="text-decoration: underline;">convertToEnglishNumber</span> and <span style="text-decoration: underline;">convertToBanglaNumber</span> functions.</p>
<p>And here goes the page where I am executing the <span style="text-decoration: underline;">displayTotalPayment()</span> function.</p>
<p>{code type=PHP}<br />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><br />
<html xmlns="http://www.w3.org/1999/xhtml"><br />
<head><br />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></p>
<p></head></p>
<p><body><br />
<?php</p>
<p>	include_once 'class.unicode.php';<br />
	$salaryObject = new UnicodeHandler();<br />
	$salaryObject->displayTotalPayment();</p>
<p>?><br />
</body><br />
</html><br />
{/code}</p>
<p>Now the final result looks like this:</p>
<p><a href="http://www.tanzilo.com/wp-content/uploads/2008/12/add_bangla_number.jpg"><img class="alignleft size-full wp-image-61" style="float:none;" title="add_bangla_number" src="http://www.tanzilo.com/wp-content/uploads/2008/12/add_bangla_number.jpg" alt="" width="210" height="531" /></a></p>
<p>Oh! One important thing. If you are coding for European number format, you need to do some modification to handle the comma (,) factor in the number in case required.</p>
<p>Thus, if you use this small tricky method, you can add, subtract,  multiply or divide any local numbers such as Russian, Chinese, Arabic, Spanish, German, Polish, Turkey, Hindi etc.</p>
<p>You can also download this small piece of code from here:<br />
<a title="unicode number add" href="http://www.tanzilo.com/demo/code/unicode_number_add/unicode_number_add.zip" target="_blank">http://www.tanzilo.com/demo/code/unicode_number_add/unicode_number_add.zip</a></p>
<p>Thank you for reading.</p>
<p><map name='google_ad_map_60_eaab367e2f0158c1'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/60?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_60_eaab367e2f0158c1' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=60&amp;url= http%3A%2F%2Fwww.tanzilo.com%2F2008%2F12%2F23%2Fphp-mysql-unicode-number-add-subtract-etc-for-any-language%2F' /></p>]]></content:encoded>
			<wfw:commentRss>http://www.tanzilo.com/2008/12/23/php-mysql-unicode-number-add-subtract-etc-for-any-language/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>WordPress: get page id and content with example &amp; code</title>
		<link>http://www.tanzilo.com/2008/12/19/wordpress-get-page-id-and-content-with-example-code/</link>
		<comments>http://www.tanzilo.com/2008/12/19/wordpress-get-page-id-and-content-with-example-code/#comments</comments>
		<pubDate>Fri, 19 Dec 2008 16:44:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[content]]></category>
		<category><![CDATA[Example]]></category>
		<category><![CDATA[GET]]></category>
		<category><![CDATA[id]]></category>
		<category><![CDATA[page content]]></category>
		<category><![CDATA[page id]]></category>
		<category><![CDATA[print]]></category>

		<guid isPermaLink="false">http://www.tanzilo.com/?p=58</guid>
		<description><![CDATA[Hey Guys! Often I see people coming to my site searching with the terms wordpress get page id, wordpress get page content or something similar. I think wordpress developers face situations when they need to get page or post information in customized way. It happened to me too and I would like to share it [...]]]></description>
			<content:encoded><![CDATA[<p>Hey Guys!</p>
<p>Often I see people coming to my site searching with the terms <span style="text-decoration: underline;"><strong>wordpress get page id</strong></span>, <span style="text-decoration: underline;"><strong>wordpress get page content</strong></span> or something similar. I think wordpress developers face situations when they need to get page or post information in customized way. It happened to me too and I would like to share it with others since often people are coming to search this information.</p>
<p>Well. It is very easy and we can solve it quickly.<br />
OK. Now let me show you how to get these information.</p>
<p>Remember one thing that is important for wordpress data fetching of this kind. Your posts and pages information is saved in a single database table and that is <strong>wp_posts</strong>. The <strong>wp_</strong> is the prefix of you database and may differ. But most of the times the database table name is <strong>wp_posts</strong> and other times it is <strong>YourCustomPrefix_posts</strong>. We are going to fetch data from this table.</p>
<p><span style="text-decoration: underline;"><strong>WordPress &#8211; print page id:</strong></span></p>
<p>There is a built-in wordpress function using which you can print the post or page id. When you call this, this directly prints this inforation in your page without the need to use the built-in PHP <span style="text-decoration: underline;"><strong>echo</strong></span> or <span style="text-decoration: underline;"><strong>print</strong></span> function. Remember to keep it in the while loop.</p>
<p>{code type=PHP}<br />
<?php if (have_posts()) : ?></p>
<p>	<?php while (have_posts()) : the_post(); ?></p>
<p>		<?php the_ID(); ?></p>
<p>	<?php endwhile; ?></p>
<p><?php endif; ?><br />
{/code}</p>
<p><span style="text-decoration: underline;"><strong>WordPress &#8211; get page id:</strong></span></p>
<p>There is a global variable post which contains the related information of the currest post or page. The name of the variable is: <span style="text-decoration: underline;">$post</span> and it is actually an object. You can access information just as you access variables from an object. Remember to keep it in the while loop.</p>
<p>{code type=PHP}<br />
<?php if (have_posts()) : ?></p>
<p>	<?php while (have_posts()) : the_post(); ?></p>
<p>        <?php<br />
		global $post;<br />
		echo $post->ID;<br />
        ?></p>
<p>	<?php endwhile; ?></p>
<p><?php endif; ?><br />
{/code}</p>
<p>You can print all the information in the $post object to see all the variables and their values that is contains.</p>
<p>{code type=PHP}<br />
<?php if (have_posts()) : ?></p>
<p>	<?php while (have_posts()) : the_post(); ?></p>
<p>        <?php<br />
		global $post;<br />
		var_dump($post);<br />
        ?></p>
<p>	<?php endwhile; ?></p>
<p><?php endif; ?><br />
{/code}</p>
<p><span style="text-decoration: underline;"><strong>WordPress &#8211; get page content:</strong></span></p>
<p>Now you know you can get the page or post content from $post-&gt;post_content variable. But if you echo or print them, they may look somewhat without formatting. So, you need to use PHP built-in <strong>nl2br()</strong> function to look the content as it is.</p>
<p>{code type=PHP}<br />
<?php if (have_posts()) : ?></p>
<p>	<?php while (have_posts()) : the_post(); ?></p>
<p>        <?php<br />
		global $post;<br />
		echo nl2br($post->post_content);<br />
        ?></p>
<p>	<?php endwhile; ?></p>
<p><?php endif; ?><br />
{/code}</p>
<p><span style="text-decoration: underline;"><strong>WordPress &#8211; get any information of your page or post:</strong></span></p>
<p>You know you can print all information to check all the available variables and their values through using PHP&#8217;s built-in <strong>var_dump()</strong> function. Suppose you need to get the post title, post type and posting time. We can get them easily in this way.</p>
<p>{code type=PHP}<br />
<?php if (have_posts()) : ?></p>
<p>	<?php while (have_posts()) : the_post(); ?></p>
<p>        <?php<br />
		global $post;<br />
		echo $post->post_title;<br />
		echo $post->post_type;<br />
		echo $post->post_date;<br />
        ?></p>
<p>	<?php endwhile; ?></p>
<p><?php endif; ?><br />
{/code}</p>
<p>Please notice that post_title, post_type and post_date are all several database fields from <strong>wp_posts</strong> table of our wordpress database.</p>
<p>Very easy. Right? And that is all for getting the page or post information.</p>
<p>Thank you for reading.</p>
<p><map name='google_ad_map_58_eaab367e2f0158c1'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/58?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_58_eaab367e2f0158c1' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=58&amp;url= http%3A%2F%2Fwww.tanzilo.com%2F2008%2F12%2F19%2Fwordpress-get-page-id-and-content-with-example-code%2F' /></p>]]></content:encoded>
			<wfw:commentRss>http://www.tanzilo.com/2008/12/19/wordpress-get-page-id-and-content-with-example-code/feed/</wfw:commentRss>
		<slash:comments>43</slash:comments>
		</item>
		<item>
		<title>WordPress: Custom URL rewrite and reading URL values</title>
		<link>http://www.tanzilo.com/2008/12/17/wordpress-custom-url-rewrite-and-reading-url-values/</link>
		<comments>http://www.tanzilo.com/2008/12/17/wordpress-custom-url-rewrite-and-reading-url-values/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 20:48:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[Custom]]></category>
		<category><![CDATA[read]]></category>
		<category><![CDATA[rewrite]]></category>
		<category><![CDATA[URL]]></category>
		<category><![CDATA[values]]></category>

		<guid isPermaLink="false">http://www.tanzilo.com/?p=59</guid>
		<description><![CDATA[Hello! Recently I was working for a Irish guy who has opened a wordpress blog few months ago. I did the theme for him. Recently he requested me for modifying and/or upgrading the project. One of the project requirements was URL rewriting. For example, there can a URL as follows: http://www.sitename.com/index.php?group_name=My-Input-Value-Goes-Here But after rewrite, the [...]]]></description>
			<content:encoded><![CDATA[<p>Hello!</p>
<p>Recently I was working for a Irish guy who has opened a wordpress blog few months ago. I did the theme for him. Recently he requested me for modifying and/or upgrading the project. One of the project requirements was URL rewriting. For example, there can a URL as follows:<br />
<strong>http://www.sitename.com/index.php?group_name=My-Input-Value-Goes-Here</strong></p>
<p>But after rewrite, the URL should look like:<br />
<strong>http://www.sitename.com/My-Input-Value-Goes-Here</strong></p>
<p>Well. You see I am passing the variable value in <span style="text-decoration: underline;">index.php</span> file. But I needed to read the custom URL passed value through another PHP file and that is <span style="text-decoration: underline;">group.php</span>. My <span style="text-decoration: underline;">group.php</span> file was inside the theme folder. I am passing the <strong>group_name</strong> value in <span style="text-decoration: underline;">index.php</span> file but reading from <span style="text-decoration: underline;">group.php</span> file. It sounds a bit interesting. Huh?</p>
<p>OK. After browsing several blogs, I came up to writing a custom plugin. Thanks to Google.com and all those people sharing information.</p>
<p>My plugin made me a way so that I could pass a variable value in <span style="text-decoration: underline;">index.php</span> file but read it from <span style="text-decoration: underline;">group.php</span> file. This plugin code is available almost everywhere. Here goes my plugin:</p>
<p>{code type=PHP}<br />
<?php</p>
<p>	/*<br />
	Plugin Name: WP Custom URL<br />
	Plugin URI: http://www.tanzilo.com/#<br />
	Description: A plugin to allow parameters to be passed in the URL and recognized by WordPress<br />
	Author: Tanzilo<br />
	Version: 1.0<br />
	Author URI: http://www.tanzilo.com/<br />
	*/</p>
<p>	function flush_rewrite_rules()<br />
	{<br />
		global $wp_rewrite;<br />
		$wp_rewrite->flush_rules();<br />
	}</p>
<p>	function add_rewrite_rules( $wp_rewrite )<br />
	{<br />
		$new_rules = array(<br />
	  		&#8216;(.+)&#8217; => &#8216;index.php?group_name=&#8217; .<br />
			$wp_rewrite->preg_index(1) );</p>
<p>		$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;<br />
	}</p>
<p>	function add_query_vars( $qvars )<br />
	{<br />
		$qvars[] = &#8216;group_name&#8217;;<br />
		return $qvars;<br />
	}</p>
<p>	function template_redirect_file()<br />
	{<br />
		global $wp_query;<br />
		if ( $wp_query->get(&#8216;group_name&#8217;) )<br />
		{<br />
			if (file_exists( TEMPLATEPATH . &#8216;/group.php&#8217; ))<br />
			{<br />
				include( TEMPLATEPATH . &#8216;/group.php&#8217; );<br />
				exit;<br />
			}<br />
		}<br />
	}</p>
<p>	add_action(&#8216;init&#8217;, &#8216;flush_rewrite_rules&#8217;);<br />
	add_action(&#8216;generate_rewrite_rules&#8217;, &#8216;add_rewrite_rules&#8217;);<br />
	add_filter(&#8216;query_vars&#8217;, &#8216;add_query_vars&#8217;);<br />
	add_action(&#8216;template_redirect&#8217;, &#8216;template_redirect_file&#8217;);</p>
<p>?><br />
{/code}</p>
<p>So, what happens now when I activate this plugin? It does a simple work and that is: when it gets a link as below:<br />
<strong>http://www.sitename.com/index.php?group_name=My-Input-Value-Goes-Here</strong></p>
<p>It sends the <strong>group_name</strong> variable value to <span style="text-decoration: underline;">group.php</span> file which is in the theme folder. In <strong>group.php</strong> file, I can catch the variable value and use it anyway I want.</p>
<p>Do you want to see my <span style="text-decoration: underline;">group.php</span> file too? OK. Here it goes:</p>
<p>{code type=PHP}<br />
	<?php get_header(); ?></p>
<p>	<?php</p>
<p>		$group_name = $_GET['group_name'];<br />
		$group_name = str_replace('-', ' ', $group_name);</p>
<p>	?></p>
<div id="container">
<div id="contentLeft">
<div id="pageContent">
<div id="postTitle"><?php echo $group_name; ?></div>
<div id="postContent"><?php the_time('F j, Y') ?></p>
<ul id="pageGroupLinks">
                        <?php echo getGroupPageLinks($group_name); ?>
                    </ul>
</p></div>
<div id="rssSubscribe">If you enjoyed this post, make sure you<br />
                <a href="<?php bloginfo('rss2_url'); ?>&#8220;>subscribe to our RSS feed!</a>
                </div>
</p></div>
</p></div>
<p>	<?php get_sidebar(); ?></p></div>
<p>	<?php get_footer(); ?></p>
<p>{/code}</p>
<p>This was half the way winning the battle.</p>
<p>But why? Because the following lines should solve my problem.</p>
<p>{code type=PHP}<br />
	function add_rewrite_rules( $wp_rewrite )<br />
	{<br />
		$new_rules = array(<br />
	  		&#8216;(.+)&#8217; => &#8216;index.php?group_name=&#8217; .<br />
			$wp_rewrite->preg_index(1) );</p>
<p>		$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;<br />
	}<br />
{/code}</p>
<p>But for any unknown reason it was not working.</p>
<p>So, I had to take help of apache <span style="text-decoration: underline;">(dot)htaccess</span> file for solving the rest of the part.</p>
<p>I was searching for a helpful blog link and after searching many blogs, I found a similar blog article and here it is:</p>
<p><a title="URL ReWriting Link" href="http://www.webmasterworld.com/forum92/6079.htm" target="_blank">http://www.webmasterworld.com/forum92/6079.htm</a></p>
<p>In this blog, I found a similar solution and wrote my own based on this code.</p>
<p>{code type=HTML}<br />
# Enable mod_rewrite, start rewrite engine<br />
Options +FollowSymLinks<br />
RewriteEngine on<br />
#<br />
# Internally rewrite search engine friendly static URL to dynamic filepath and query<br />
RewriteRule ^product/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ /index.php?product=$1&#038;color=$2&#038;size=$3&#038;texture=$4&#038;maker=$5 [L]<br />
#<br />
# Externally redirect client requests for old dynamic URLs to equivalent new static URLs<br />
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?product=([^&#038;]+)&#038;color=([^&#038;]+)&#038;size=([^&#038;]+)&#038;texture=([^&#038;]+)&#038;maker=([^\ ]+)\ HTTP/<br />
RewriteRule ^index\.php$ http://example.com/product/%1/%2/%3/%4/%5? [R=301,L]<br />
{/code}</p>
<p>Finally my <span style="text-decoration: underline;">(dot)htaccess</span> file looked like this:</p>
<p>{code type=HTML}<br />
# BEGIN WordPress<br />
<IfModule mod_rewrite.c><br />
RewriteEngine On<br />
RewriteBase /</p>
<p>RewriteRule ^pages/([^/]+)/?$ /index.php?group_name=$1 [L]<br />
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?group_name=([^&#038;]+)\ HTTP/<br />
RewriteRule ^index\.php$ http://mobile.ie/pages/%1? [R=301,L] </p>
<p>RewriteCond %{REQUEST_FILENAME} !-f<br />
RewriteCond %{REQUEST_FILENAME} !-d<br />
RewriteRule . /index.php [L]<br />
</IfModule></p>
<p># END WordPress<br />
{/code}</p>
<p>But I was not 100% perfect but close to the solution. The reason is my URL started looking like this:<br />
<strong>http://www.sitename.com/pages/My-Input-Value-Goes-Here</strong></p>
<p>Well. You see I was almost close to the solution. As the buyer wanted like this:<br />
<strong>http://www.sitename.com/My-Input-Value-Goes-Here</strong></p>
<p>But I came up with a solution to:<br />
<strong>http://www.sitename.com/pages/My-Input-Value-Goes-Here</strong></p>
<p>I believe you can work on it and come to a solution without the extra &#8220;<strong>pages/</strong>&#8221; part in the URL. If you find such a solution, please share with me and others who will face similar problem.</p>
<p>Dude! That is all for now.</p>
<p>Thank you for reading.</p>
<p><map name='google_ad_map_59_eaab367e2f0158c1'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/59?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_59_eaab367e2f0158c1' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=59&amp;url= http%3A%2F%2Fwww.tanzilo.com%2F2008%2F12%2F17%2Fwordpress-custom-url-rewrite-and-reading-url-values%2F' /></p>]]></content:encoded>
			<wfw:commentRss>http://www.tanzilo.com/2008/12/17/wordpress-custom-url-rewrite-and-reading-url-values/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>WordPress: Upload many PHP files quickly by Zip &amp; Unzip</title>
		<link>http://www.tanzilo.com/2008/12/15/wordpress-upload-many-php-files-quickly-by-zip-unzip/</link>
		<comments>http://www.tanzilo.com/2008/12/15/wordpress-upload-many-php-files-quickly-by-zip-unzip/#comments</comments>
		<pubDate>Mon, 15 Dec 2008 21:29:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[fast]]></category>
		<category><![CDATA[files]]></category>
		<category><![CDATA[many]]></category>
		<category><![CDATA[quickly]]></category>
		<category><![CDATA[Upload]]></category>

		<guid isPermaLink="false">http://www.tanzilo.com/?p=56</guid>
		<description><![CDATA[Hello! It is actually not only for a wordpress developer but also for all those developers who face situation where they must upload many files to the server. Recently in a wordpress project, I had to upload wordpress 2.7 version files in the server. In the wordpress 2.7 package, you will find around 600 files! [...]]]></description>
			<content:encoded><![CDATA[<p>Hello!</p>
<p>It is actually not only for a wordpress developer but also for all those developers who face situation where they must upload many files to the server. Recently in a wordpress project, I had to upload wordpress 2.7 version files in the server. In the wordpress 2.7 package, you will find around 600 files! Uploading them is not very interesting when your internet connection do not guarantee you smooth upload.</p>
<p>Uploading the 600 files brought me pain because they were going to the server very slowly and each time some files were corrupted and for any reason reuploading the corrupted files were not working. It was really time consuming, boring and painful. Then I started to look for an alternative solution. Then, I naturally came to the idea that how about I zip (compress) the folders containing most of the files and upload them. Thus I have to upload few zip files although bigger in size. Writing a piece of PHP code to unzip the zipped file is easy too.</p>
<p>So, I decided to zip the main three folders and uploaded them. You know they contain most of the files.</p>
<p>OK. Let me tell you the process in step by step way so that you can follow easily:</p>
<ol>
<li>First I zipped my three folders (<strong>wp-admin</strong>, <strong>wp-content</strong> &amp; <strong>wp-includes</strong>) that contains most of the files.</li>
<li>Changed the &#8216;<span style="text-decoration: underline;"><strong>public_html</strong></span>&#8216; folder permission to 777. Remember you will do it for the folder where you are going to upload.</li>
<li>Uploaded the three zipped folders.</li>
<li>Run my PHP script that you will see below.</li>
<li>Checked if everything is OK and found them OK.</li>
<li>Changed the file permission of the &#8216;<span style="text-decoration: underline;"><strong>public_html</strong></span>&#8216; folder back to 750. If you uploaded to any other folder, you need to change the permission 777 to any combination you think good for your purpose.</li>
<li>Deleted the zip files since they are no longer required.</li>
</ol>
<p>Here goes my PHP code to unzip them and it is very simple!</p>
<p>{code type=PHP}<br />
<?php </p>
<p>	$zipFileNames = array();<br />
	$zipFileNames[] = 'wp-admin.zip';<br />
	$zipFileNames[] = 'wp-content.zip';<br />
	$zipFileNames[] = 'wp-includes.zip';<br />
	// and all other zip files</p>
<p>	$indexLimit = count($zipFileNames);<br />
	for($i=0; $i<$indexLimit; $i++)<br />
	{<br />
		$fileLink = $_SERVER['DOCUMENT_ROOT'] . '/' . $zipFileNames[$i];<br />
		if(is_file($fileLink))<br />
		{<br />
			if(exec("unzip $fileLink"))<br />
			{<br />
				echo 'Successful! ' . $fileLink . ' is properly unzipped!' . '<br />&#8216;;<br />
			}<br />
			else<br />
			{<br />
				echo &#8216;Failed! exec() failed to execute as expected!&#8217; . &#8216;<br />&#8216; .<br />
				&#8216;Please check if the directory permission is 777 where you are trying upload.&#8217;;<br />
			}<br />
		}<br />
		else<br />
		{<br />
			echo &#8216;Error: &#8216; . $fileLink . &#8216; is not a (zip) file!&#8217; . &#8216;<br />&#8216;;<br />
		}<br />
	}</p>
<p>?><br />
{/code}</p>
<p>By the way, you can improve the code to more sophisticated one as per your requirement. For example, the <strong>exec()</strong> function has several options that you can use for more flexibility or anyway anything else you want.</p>
<p>Oh! There is one other way to unzip a uploaded zipped file although I did not use this piece of code. But remember that if you use this code you need to set your destination file permission to &#8217;777&#8242; first and then change as mentioned before after you unzipped. Fortunately this coding is very simple too and an example is as follows:</p>
<p>{code type=PHP}<br />
<?php </p>
<p>	$zip = new ZipArchive;</p>
<p>	if($zip->open($_SERVER['DOCUMENT_ROOT'] . &#8216;/hello.zip&#8217;) === true)<br />
	{<br />
		$zip->extractto($_SERVER['DOCUMENT_ROOT'] . &#8216;/hellotest/&#8217;);<br />
		$zip->close();<br />
		echo &#8216;Files successfully unzipped!&#8217;;<br />
	}<br />
	else<br />
	{<br />
		die(&#8216;Failed to open zip file&#8217;);<br />
	} </p>
<p>?><br />
{/code}</p>
<p>I tested both the processes mentioned above in Linux system and not sure how it works in Windows Server. I guess the second process should work in Windows server for uploading and unzipping bulk file quickly.</p>
<p>This is all for the trick of the game and for killing the pain of uploading several hundred of files.</p>
<p>Well. You can download my little sweet code here too:<br />
<a title="Wordpress: Upload many PHP files quickly by Zip &amp; Unzip" href="http://www.tanzilo.com/demo/code/unzip/unzipping.zip" target="_blank">http://www.tanzilo.com/demo/code/unzip/unzipping.zip</a></p>
<p>Thank you for reading.</p>
<p><map name='google_ad_map_56_eaab367e2f0158c1'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/56?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_56_eaab367e2f0158c1' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=56&amp;url= http%3A%2F%2Fwww.tanzilo.com%2F2008%2F12%2F15%2Fwordpress-upload-many-php-files-quickly-by-zip-unzip%2F' /></p>]]></content:encoded>
			<wfw:commentRss>http://www.tanzilo.com/2008/12/15/wordpress-upload-many-php-files-quickly-by-zip-unzip/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 1.376 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2012-02-06 19:47:41 -->

