<?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>A K Chauhan's Blog</title>
	<atom:link href="http://www.akchauhan.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.akchauhan.com</link>
	<description>PHP, MySql, JavaScript, JQuery, Prototype, Drupal, HTML, CSS and more...</description>
	<lastBuildDate>Tue, 13 Mar 2012 19:43:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Change text box value in uppercase using jQuery</title>
		<link>http://www.akchauhan.com/change-text-box-value-in-uppercase-using-jquery/</link>
		<comments>http://www.akchauhan.com/change-text-box-value-in-uppercase-using-jquery/#comments</comments>
		<pubDate>Tue, 27 Sep 2011 00:15:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Beginners]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.akchauhan.com/?p=715</guid>
		<description><![CDATA[We can bind this functionality with text box KeyUp event. So, when type anything this code will change the text box value in uppercase with each keystroke. Code Snippet:- &#60;input type=&#34;text&#34; id=&#34;variable&#34; name=&#34;variable&#34; /&#62; &#60;script type=&#34;text/javascript&#34;&#62; $&#40;document&#41;.ready&#40;function&#40;&#41; &#123; $&#40;'#variable'&#41;.keyup&#40;function&#40;&#41; &#123; $&#40;this&#41;.val&#40;$&#40;this&#41;.val&#40;&#41;.toUpperCase&#40;&#41;&#41;; &#125;&#41;; &#125;&#41;; &#60;/script&#62;]]></description>
			<content:encoded><![CDATA[<p>We can bind this functionality with text box KeyUp event. So, when type anything this code will change the text box value in uppercase with each keystroke. </p>
<p>Code Snippet:-</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;input type=&quot;text&quot; id=&quot;variable&quot; name=&quot;variable&quot; /&gt;</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#variable'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">keyup</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toUpperCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.akchauhan.com/change-text-box-value-in-uppercase-using-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery get selected text from SELECT (or DROPDOWN) list box</title>
		<link>http://www.akchauhan.com/jquery-get-selected-text-from-select-or-dropdown-list-box/</link>
		<comments>http://www.akchauhan.com/jquery-get-selected-text-from-select-or-dropdown-list-box/#comments</comments>
		<pubDate>Thu, 08 Sep 2011 14:49:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Beginners]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.akchauhan.com/?p=707</guid>
		<description><![CDATA[Most of the time in JavaScript we want to do following things with Select (or dropdown) list box. - Get the value of selected option - Get the text of selected option - Get the text of option using its value We can use jQuery for all of the above tasks. jQuery provide very simple [...]]]></description>
			<content:encoded><![CDATA[<p>Most of the time in JavaScript we want to do following things with Select (or dropdown) list box.</p>
<p>- Get the value of selected option<br />
- Get the text of selected option<br />
- Get the text of option using its value</p>
<p>We can use <a href="http://jquery.com/" title="jQuery" target="_blank">jQuery</a> for all of the above tasks. <a href="http://jquery.com/" title="jQuery" target="_blank">jQuery</a> provide very simple one line solution for all of them. Find below code snippet of all three one by one.</p>
<p>Code Snippet:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Select list box</span>
<span style="color: #339933;">&lt;</span>select id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;dropdown&quot;</span><span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;0&quot;</span><span style="color: #339933;">&gt;</span>Sunday<span style="color: #339933;">&lt;/</span>option<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;1&quot;</span><span style="color: #339933;">&gt;</span>Monday<span style="color: #339933;">&lt;/</span>option<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;2&quot;</span><span style="color: #339933;">&gt;</span>Tuesday<span style="color: #339933;">&lt;/</span>option<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;3&quot;</span> selected<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;selected&quot;</span><span style="color: #339933;">&gt;</span>Wednesday<span style="color: #339933;">&lt;/</span>option<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;4&quot;</span><span style="color: #339933;">&gt;</span>Thursday<span style="color: #339933;">&lt;/</span>option<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;5&quot;</span><span style="color: #339933;">&gt;</span>Friday<span style="color: #339933;">&lt;/</span>option<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;6&quot;</span><span style="color: #339933;">&gt;</span>Saturday<span style="color: #339933;">&lt;/</span>option<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>select<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Get the value of selected option</span>
<span style="color: #003366; font-weight: bold;">var</span> selectedvalue <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#dropdown'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>selectedvalue<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// 3</span>
&nbsp;
&nbsp;
<span style="color: #006600; font-style: italic;">// Get the text of selected option</span>
<span style="color: #003366; font-weight: bold;">var</span> selectedText <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#dropdown option:selected'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>selectedText<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// Wednesday</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Get the text of option using its option value (eg: 5)</span>
<span style="color: #003366; font-weight: bold;">var</span> textThroughValue <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#dropdown option[value='5']&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>textThroughValue<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// Friday</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.akchauhan.com/jquery-get-selected-text-from-select-or-dropdown-list-box/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Extract/Import Object properties into Currect Symbol Table in PHP</title>
		<link>http://www.akchauhan.com/extractimport-object-properties-into-currect-symbol-table-in-php/</link>
		<comments>http://www.akchauhan.com/extractimport-object-properties-into-currect-symbol-table-in-php/#comments</comments>
		<pubDate>Thu, 01 Sep 2011 23:17:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Beginners]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.akchauhan.com/?p=701</guid>
		<description><![CDATA[If we want to import an associative array into current symbol table then we can use extract function. This function treats associative array keys as variable name and values as variable values. But we can not use extract function directly if we want to import class object properties into current symbol table in similar way. [...]]]></description>
			<content:encoded><![CDATA[<p>If we want to import an associative array into current symbol table then we can use <a href="http://php.net/manual/en/function.extract.php" title="extract Function" target="_blank"><strong>extract</strong></a> function. This function treats associative array keys as variable name and values as variable values.  </p>
<p>But we can not use <a href="http://php.net/manual/en/function.extract.php" title="extract Function" target="_blank"><strong>extract</strong></a> function directly if we want to import class object properties into current symbol table in similar way. So, for this first we need to get the properties of object as an associated array. We can use <a href="http://in3.php.net/manual/en/function.get-object-vars.php" title="get_object_vars function"><strong>get_object_vars</strong></a> function for this purpose. <a href="http://in3.php.net/manual/en/function.get-object-vars.php" title="get_object_vars function"><strong>get_object_vars</strong></a> function take object as parameter and return associative array of all non-static properties of passed object. For any unassigned property it will return <em>NULL</em> value. </p>
<p>Now we can pass this returned associative array into <a href="http://php.net/manual/en/function.extract.php" title="extract Function" target="_blank"><strong>extract</strong></a> function to import objects non-static properties into current symbol table.</p>
<p>Code Snippet:-</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// For associative array</span>
&nbsp;
<span style="color: #000088;">$sampleArray</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'John'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'age'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">25</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">extract</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sampleArray</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$name</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Output is &quot;John&quot;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$age</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Output is &quot;25&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// For object</span>
<span style="color: #000088;">$sampleObject</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> stdClass<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$sampleObject</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Peter'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$sampleObject</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">age</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">27</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$returnArray</span> <span style="color: #339933;">=</span> <span style="color: #990000;">get_object_vars</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sampleObject</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">extract</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$returnArray</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$name</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Output is &quot;Peter&quot;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$age</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Output is &quot;27&quot;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.akchauhan.com/extractimport-object-properties-into-currect-symbol-table-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generate Random Alphanumeric Password in PHP</title>
		<link>http://www.akchauhan.com/generate-random-alphanumeric-password-in-php/</link>
		<comments>http://www.akchauhan.com/generate-random-alphanumeric-password-in-php/#comments</comments>
		<pubDate>Sun, 28 Aug 2011 05:59:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Beginners]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.akchauhan.com/?p=695</guid>
		<description><![CDATA[This is a very simple and one of the way to generate random alphanumeric password in PHP. Code Snippet:- &#60;?php function generateCharacter&#40;&#41; &#123; $possible = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $char = substr&#40;$possible, mt_rand&#40;0, strlen&#40;$possible&#41; - 1&#41;, 1&#41;; return $char; &#125; &#160; function generatePassword&#40;$length&#41; &#123; static $password; &#160; if &#40;$length&#41; &#123; $password .= generateCharacter&#40;&#41;; &#160; generatePassword&#40;--$length&#41;; &#125; &#160; return [...]]]></description>
			<content:encoded><![CDATA[<p>This is a very simple and one of the way to generate random alphanumeric password in PHP.</p>
<p>Code Snippet:-</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">function</span> generateCharacter<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$possible</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$char</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$possible</span><span style="color: #339933;">,</span> <span style="color: #990000;">mt_rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$possible</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$char</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> generatePassword<span style="color: #009900;">&#40;</span><span style="color: #000088;">$length</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	static <span style="color: #000088;">$password</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$length</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$password</span> <span style="color: #339933;">.=</span> generateCharacter<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		generatePassword<span style="color: #009900;">&#40;</span><span style="color: #339933;">--</span><span style="color: #000088;">$length</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$password</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Use of this function</span>
&nbsp;
<span style="color: #b1b100;">echo</span> generatePassword<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Qz1GUfkWFT</span>
<span style="color: #b1b100;">echo</span> generatePassword<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">15</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// GPB1hA8pVVWsgLZ</span>
<span style="color: #b1b100;">echo</span> generatePassword<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">8</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// 20e3Bvec</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.akchauhan.com/generate-random-alphanumeric-password-in-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP Class for converting XML to Object and Object to XML</title>
		<link>http://www.akchauhan.com/php-class-for-converting-xml-to-object-and-object-to-xml/</link>
		<comments>http://www.akchauhan.com/php-class-for-converting-xml-to-object-and-object-to-xml/#comments</comments>
		<pubDate>Thu, 28 Jul 2011 18:53:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Array]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.akchauhan.com/?p=681</guid>
		<description><![CDATA[Sometimes in PHP we need to convert PHP object into XML string and vice versa. Conversion of XML string to PHP object is pretty simple. You just need to call simplexml_load_string() function (available in PHP 5+) and need to pass your XML string. This will return the object which you can use. The only requirement [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes in PHP we need to convert PHP object into XML string and vice versa. Conversion of XML string to PHP object is pretty simple. You just need to call <a href="http://php.net/manual/en/function.simplexml-load-string.php" target="_blank"><strong>simplexml_load_string()</strong></a> function (available in PHP 5+) and need to pass your XML string. This will return the object which you can use. The only requirement is your XML string need to be well-formed XML string otherwise PHP will through <strong>E_WARNING</strong> error message.</p>
<p>Conversion of Object into XML string is little bit tricky. We need to recursively parse the Object and need to create XML tags for object attributes (keys). I&#8217;m using <a href="http://php.net/manual/en/book.xmlwriter.php" target="_blank"><strong>XmlWriter</strong></a> class for that purpose. Three important methods of this class which I&#8217;m using is <a href="http://www.php.net/manual/en/function.xmlwriter-start-element.php" target="_blank"><strong>startElement()</strong></a>, <a href="http://www.php.net/manual/en/function.xmlwriter-end-element.php" target="_blank"><strong>endElement()</strong></a>, and <a href="http://www.php.net/manual/en/function.xmlwriter-write-element.php" target="_blank"><strong>writeElement()</strong></a>. We need to check the passed mixed variable in getObject2XML() method and add the XML tags with values one by one.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> ObjectAndXML <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> static <span style="color: #000088;">$xml</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Constructor</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">xml</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> XmlWriter<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">xml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">openMemory</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">xml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">startDocument</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'1.0'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">xml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setIndent</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Method to convert Object into XML string</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> objToXML<span style="color: #009900;">&#40;</span><span style="color: #000088;">$obj</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getObject2XML</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">xml</span><span style="color: #339933;">,</span> <span style="color: #000088;">$obj</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">xml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">endElement</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">xml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">outputMemory</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Method to convert XML string into Object</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> xmlToObj<span style="color: #009900;">&#40;</span><span style="color: #000088;">$xmlString</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #990000;">simplexml_load_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xmlString</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> getObject2XML<span style="color: #009900;">&#40;</span>XMLWriter <span style="color: #000088;">$xml</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">is_object</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$xml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">startElement</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getObject2XML</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xml</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$xml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">endElement</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getArray2XML</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xml</span><span style="color: #339933;">,</span> <span style="color: #000088;">$key</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">is_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$xml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">writeElement</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> getArray2XML<span style="color: #009900;">&#40;</span>XMLWriter <span style="color: #000088;">$xml</span><span style="color: #339933;">,</span> <span style="color: #000088;">$keyParent</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">is_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$xml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">writeElement</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$keyParent</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">is_numeric</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$xml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">startElement</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$keyParent</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">is_object</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getObject2XML</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xml</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getArray2XML</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xml</span><span style="color: #339933;">,</span> <span style="color: #000088;">$key</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">is_numeric</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$xml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">endElement</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p><strong>How to use it.</strong><br />
1. If you want to convert XML string into PHP object.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$obj</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ObjectAndXML<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$str</span> <span style="color: #339933;">=</span> <span style="color: #0000cc; font-style: italic;">&lt;&lt;&lt;STR
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;records&gt;
    &lt;person&gt;
    	&lt;name&gt;XYZ&lt;/name&gt;
        &lt;age&gt;28&lt;/age&gt;
        &lt;gender&gt;Male&lt;/gender&gt;
    &lt;/person&gt;
    &lt;person&gt;
    	&lt;name&gt;ABC&lt;/name&gt;
        &lt;age&gt;25&lt;/age&gt;
        &lt;gender&gt;Male&lt;/gender&gt;
    &lt;/person&gt;
&lt;/records&gt;
STR</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$recordsObj</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$obj</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">xmlToObj</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;pre&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$recordsObj</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Above code will give you this output on browser</span>
<span style="color: #666666; font-style: italic;">/*
object(SimpleXMLElement)#3 (1) {
  [&quot;person&quot;]=&gt;
  array(2) {
    [0]=&gt;
    object(SimpleXMLElement)#4 (3) {
      [&quot;name&quot;]=&gt;
      string(3) &quot;XYZ&quot;
      [&quot;age&quot;]=&gt;
      string(2) &quot;28&quot;
      [&quot;gender&quot;]=&gt;
      string(4) &quot;Male&quot;
    }
    [1]=&gt;
    object(SimpleXMLElement)#5 (3) {
      [&quot;name&quot;]=&gt;
      string(3) &quot;ABC&quot;
      [&quot;age&quot;]=&gt;
      string(2) &quot;25&quot;
      [&quot;gender&quot;]=&gt;
      string(4) &quot;Male&quot;
    }
  }
}
*/</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// If you want to access value of &quot;name&quot; tag under second &quot;person&quot; tag then you can use </span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$recordsObj</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">person</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>2. If you want to convert PHP object into XML string.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$obj</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ObjectAndXML<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$objData1</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> stdClass<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$objData1</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">records</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">person</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'XYZ'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$objData1</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">records</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">person</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">age</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'28'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$objData1</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">records</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">person</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">gender</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Male'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$objData1</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">records</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">person</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'ABC'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$objData1</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">records</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">person</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">age</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'25'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$objData1</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">records</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">person</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">gender</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Male'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$recordsXML</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$obj</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">objToXML</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$objData1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Output will be</span>
<span style="color: #666666; font-style: italic;">/*
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;records&gt;
 &lt;person&gt;
  &lt;name&gt;XYZ&lt;/name&gt;
  &lt;age&gt;28&lt;/age&gt;
  &lt;gender&gt;Male&lt;/gender&gt;
 &lt;/person&gt;
 &lt;person&gt;
  &lt;name&gt;ABC&lt;/name&gt;
  &lt;age&gt;25&lt;/age&gt;
  &lt;gender&gt;Male&lt;/gender&gt;
 &lt;/person&gt;
&lt;/records&gt;
*/</span>
&nbsp;
<span style="color: #000088;">$objData2</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> stdClass<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$objData2</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">records</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">person</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'XYZ'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$objData2</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">records</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">person</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'ABC'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$objData2</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">records</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">person</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'PQR'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$objData2</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">records</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">person</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'XYZ1'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$objData2</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">records</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">person</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'ABC1'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$objData2</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">records</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">person</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'PQR1'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$recordsXML</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$obj</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">objToXML</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$objData2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Output will be</span>
<span style="color: #666666; font-style: italic;">/*
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;records&gt;
 &lt;person&gt;
  &lt;name&gt;XYZ&lt;/name&gt;
  &lt;name&gt;ABC&lt;/name&gt;
  &lt;name&gt;PQR&lt;/name&gt;
 &lt;/person&gt;
 &lt;person&gt;
  &lt;name&gt;XYZ1&lt;/name&gt;
  &lt;name&gt;ABC1&lt;/name&gt;
  &lt;name&gt;PQR1&lt;/name&gt;
 &lt;/person&gt;
&lt;/records&gt;
*/</span>
&nbsp;
<span style="color: #000088;">$objData3</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> stdClass<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$objData3</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">records</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">person</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'XYZ'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$objData3</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">records</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">person</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">age</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'28'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$objData3</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">records</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">person</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">gender</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Male'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$recordsXML</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$obj</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">objToXML</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$objData3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Output will be</span>
<span style="color: #666666; font-style: italic;">/*
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;records&gt;
 &lt;person&gt;
  &lt;name&gt;XYZ&lt;/name&gt;
  &lt;age&gt;28&lt;/age&gt;
  &lt;gender&gt;Male&lt;/gender&gt;
 &lt;/person&gt;
&lt;/records&gt;
*/</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.akchauhan.com/php-class-for-converting-xml-to-object-and-object-to-xml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generate Crontab (Cron jobs) syntax/command using this simple tool</title>
		<link>http://www.akchauhan.com/create-crontab-cron-jobs-command-using-this-simple-tool/</link>
		<comments>http://www.akchauhan.com/create-crontab-cron-jobs-command-using-this-simple-tool/#comments</comments>
		<pubDate>Sun, 26 Dec 2010 14:34:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[cron jobs]]></category>
		<category><![CDATA[crontab]]></category>
		<category><![CDATA[tool]]></category>

		<guid isPermaLink="false">http://www.akchauhan.com/?p=650</guid>
		<description><![CDATA[Click here to Check it! Cron is a daemon used for scheduling tasks to be executed at a certain time. You can easily find great articles on Crontab or Cron daemon on the Internet. I found these articles very useful and easy to understand. 1. https://help.ubuntu.com/community/CronHowto 2. http://en.wikipedia.org/wiki/Cron Actually, here I don&#8217;t want to explain [...]]]></description>
			<content:encoded><![CDATA[<style type="text/css">
.button_cron {
   border-top: 1px solid #96d1f8;
   background: #65a9d7;
   background: -webkit-gradient(linear, left top, left bottom, from(#3e779d), to(#65a9d7));
   background: -moz-linear-gradient(top, #3e779d, #65a9d7);
   padding: 10.5px 21px;
   -webkit-border-radius: 8px;
   -moz-border-radius: 8px;
   border-radius: 8px;
   -webkit-box-shadow: rgba(0,0,0,1) 0 1px 0;
   -moz-box-shadow: rgba(0,0,0,1) 0 1px 0;
   box-shadow: rgba(0,0,0,1) 0 1px 0;
   text-shadow: rgba(0,0,0,.4) 0 1px 0;
   color: white;
   font-size: 14px;
   font-family: Georgia, Serif;
   text-decoration: none;
   vertical-align: middle;
   }
.button_cron:hover {
   border-top-color: #28597a;
   background: #28597a;
   color: #ccc;
   }
.button_cron:active {
   border-top-color: #1b435e;
   background: #1b435e;
   }
</style>
<p><div id="attachment_651" class="wp-caption aligncenter" style="width: 875px"><a href="http://www.akchauhan.com/tools/crontab/" target="_blank"><img src="http://www.akchauhan.com/wp-content/uploads/2010/12/crontab.png" alt="Create Crontab command using this simple tool" title="Create Crontab command using this simple tool" width="865" height="489" class="size-full wp-image-651" /></a><p class="wp-caption-text">Create Crontab command using this simple tool</p></div><br />
<br/>
<div style="text-align:center; width:980px;"><a href="http://www.akchauhan.com/tools/crontab/" target="_blank" class="button_cron">Click here to Check it!</a></div>
<p><br/><br />
Cron is a daemon used for scheduling tasks to be executed at a certain time. You can easily find great articles on Crontab or Cron daemon on the Internet. I found these articles very useful and easy to understand. </p>
<p>1. <a href="https://help.ubuntu.com/community/CronHowto">https://help.ubuntu.com/community/CronHowto</a><br />
2. <a href="http://en.wikipedia.org/wiki/Cron">http://en.wikipedia.org/wiki/Cron</a></p>
<p>Actually, here I don&#8217;t want to explain how crontab work and how you can schedule tasks using crontab. I just want to discuss this tool I&#8217;ve created for generating crontab entries/syntax which you can copy and directly put in your crontab file. </p>
<p>In this tool there are five sections; minute, hour, day, month and weekday. You can select single or multiple values for each section from the list which you want to use in your crontab file. </p>
<p>You may want to run a script some number of times per time section. For example if you want to run crontab job in every 10 minutes (runs on minutes divisible by 10: 0, 10, 20, 30, etc.). In this case you can use &#8220;Every (x) minute&#8221; option and select 10 from drop down list. You can also get the correct output from &#8220;Minutes(s)&#8221; list but this option will generate less cumbersome output. </p>
<p>In &#8220;Command&#8221; text box you need to enter full command you want to execute in crontab. When you click Submit you will see this command with values for different section. </p>
<p>There should be single space between each section with the final section (command) can having one or more spaces in it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.akchauhan.com/create-crontab-cron-jobs-command-using-this-simple-tool/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Verify the iTunes Account access information with the help of cURL</title>
		<link>http://www.akchauhan.com/verify-the-itunes-account-access-information-with-the-help-of-curl/</link>
		<comments>http://www.akchauhan.com/verify-the-itunes-account-access-information-with-the-help-of-curl/#comments</comments>
		<pubDate>Sun, 04 Jul 2010 20:19:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[iTunes]]></category>

		<guid isPermaLink="false">http://www.akchauhan.com/?p=646</guid>
		<description><![CDATA[&#60;?php // URLs of iTunesconnect. $urlBase = 'https://itts.apple.com'; $urlWebsite = $urlBase . '/cgi-bin/WebObjects/Piano.woa'; &#160; // function to check finance role acounts validity. This function return true is the detail is still valid. function isAccountValid&#40;$username, $password&#41; &#123; global $urlBase, $urlWebsite; &#160; $html = curlRequest&#40;$urlWebsite, null&#41;; // First cURL request to get the login form &#160; preg_match&#40;'/&#34; [...]]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// URLs of iTunesconnect.</span>
<span style="color: #000088;">$urlBase</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'https://itts.apple.com'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$urlWebsite</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$urlBase</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/cgi-bin/WebObjects/Piano.woa'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// function to check finance role acounts validity. This function return true is the detail is still valid.</span>
<span style="color: #000000; font-weight: bold;">function</span> isAccountValid<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$urlBase</span><span style="color: #339933;">,</span> <span style="color: #000088;">$urlWebsite</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> curlRequest<span style="color: #009900;">&#40;</span><span style="color: #000088;">$urlWebsite</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// First cURL request to get the login form</span>
&nbsp;
	<span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/&quot; action=&quot;.*&quot;/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$html</span><span style="color: #339933;">,</span> <span style="color: #000088;">$matches</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Search the form action URL because all URLs are dynamic</span>
&nbsp;
	<span style="color: #000088;">$urlActionLogin</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$urlBase</span> <span style="color: #339933;">.</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$matches</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$postData</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'theAccountName'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'theAccountPW'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$password</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'1.Continue.x'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'1'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'1.Continue.y'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'1'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Creating the form POST data</span>
&nbsp;
	<span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> curlRequest<span style="color: #009900;">&#40;</span><span style="color: #000088;">$urlActionLogin</span><span style="color: #339933;">,</span> <span style="color: #000088;">$postData</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Second cURL request with form data for login</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$html</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Report Options'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// If the return HTML contain 'Report Options' text then its successful login</span>
		<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// function send the curl request on given URL with post variables and return the html output</span>
<span style="color: #000000; font-weight: bold;">function</span> curlRequest<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #000088;">$postVars</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">is_null</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$postVars</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> 
		<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_POST<span style="color: #339933;">,</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$postVars</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 		<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_POSTFIELDS<span style="color: #339933;">,</span> <span style="color: #990000;">http_build_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$postVars</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
 	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_FOLLOWLOCATION<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_HEADER<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
 	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_SSL_VERIFYPEER<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
 	<span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">curl_errno</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">curl_error</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$html</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Examples 01</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>isAccountValid<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'anil@test.com'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'test@anil'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;anil@test.com account is valid.&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;anil@test.com account is not valid.&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Examples 02</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>isAccountValid<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'invalid_address@test.com'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wrong_password'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;invalid_address@test.com account is valid.&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;invalid_address@test.com account is not valid.&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.akchauhan.com/verify-the-itunes-account-access-information-with-the-help-of-curl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How know Base Path of Drupal in JavaScript</title>
		<link>http://www.akchauhan.com/how-know-base-path-of-drupal-in-javascript/</link>
		<comments>http://www.akchauhan.com/how-know-base-path-of-drupal-in-javascript/#comments</comments>
		<pubDate>Mon, 17 May 2010 10:45:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Drupal]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.akchauhan.com/?p=639</guid>
		<description><![CDATA[Sometimes you want to know about the Base Path of your Drupal installation in JavaScript. You may want to know about this path for sending the AJAX request at correct URL relatively, load the image or some other type of file on client side through JavaScript etc. Drupal provide a variable called Drupal.settings.basePath for this [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes you want to know about the Base Path of your <strong>Drupal installation</strong> in JavaScript. You may want to know about this path for sending the AJAX request at correct URL relatively, load the image or some other type of file on client side through JavaScript etc. </p>
<p>Drupal provide a variable called <strong>Drupal.settings.basePath</strong> for this purpose in JavaScript. But this variable is only available if you include any custom JavaScript file or JavaScript block in your module. By default Drupal doesn&#8217;t include the &#8216;<strong>jquery.js</strong>&#8216; and &#8216;<strong>drupal.js</strong>&#8216; file in generated output. It only add these files if you add your custom JavaScript file or JavaScript block. We can include our custom JavaScript file in Drupal like this:-</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">drupal_add_js<span style="color: #009900;">&#40;</span>drupal_get_path<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'module'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'my_module'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span> <span style="color: #0000ff;">'/my_module.js'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The <strong>my_module.js</strong> file should reside in same directory where <strong>my_module</strong> module exist. This will force Drupal to add jquery.js and drupal.js files in output.</p>
<p>These two files initialize the Base Path variable. In drupal.js file, on top you can see the initialization of setting object in Drupal object. Like this:-</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> Drupal <span style="color: #339933;">=</span> Drupal <span style="color: #339933;">||</span> <span style="color: #009900;">&#123;</span> <span style="color: #3366CC;">'settings'</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'behaviors'</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'themes'</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'locale'</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Drupal generate some JavaScript code in Script block inside head tag of each page for extending the settings object with the help of jQuery. Like this:-</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">jQuery.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span>Drupal.<span style="color: #660066;">settings</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span> <span style="color: #3366CC;">&quot;basePath&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;/&quot;</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>You can test the Base Path by adding following code in <strong>my_module.js</strong> file.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>Drupal.<span style="color: #660066;">settings</span>.<span style="color: #660066;">basePath</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This will alert the Base Path for Drupal installation after loading of the page. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.akchauhan.com/how-know-base-path-of-drupal-in-javascript/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Create Simple Carousel using jQuery</title>
		<link>http://www.akchauhan.com/create-simple-carousel-using-jquery/</link>
		<comments>http://www.akchauhan.com/create-simple-carousel-using-jquery/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 03:42:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Carousel]]></category>

		<guid isPermaLink="false">http://www.akchauhan.com/?p=607</guid>
		<description><![CDATA[You can see the working demo here. Carousel is a way to present content in the form of slideshow on web page. Here I&#8217;m showing how easily you can create a horizontal carousel using jQuery. You can play with the given code and easily create vertical carousel, circular carousel, auto-scrolling carousel etc. I&#8217;m using jQuery [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_609" class="wp-caption aligncenter" style="width: 671px"><a href="http://www.akchauhan.com/examples/carousel/" target="_blank"><img src="http://www.akchauhan.com/wp-content/uploads/2010/02/carousel.png" alt="Carousel Image" title="Carousel" width="661" height="163" class="size-full wp-image-609" /></a><p class="wp-caption-text">Carousel</p></div>
<p><strong>You can see the working demo <a href="http://www.akchauhan.com/examples/carousel/">here</a></strong>.</p>
<p><strong>Carousel </strong>is a way to present content in the form of <strong>slideshow </strong> on web page. Here I&#8217;m showing how easily you can create a horizontal carousel using <strong>jQuery</strong>. You can play with the given code and easily create <strong>vertical carousel, circular carousel, auto-scrolling carousel</strong> etc.</p>
<p>I&#8217;m using jQuery for animation. So, you need jQuery JavaScript library for it. You can download latest jQuery JavaScript library from <a href="http://jquery.com/">jquery.com</a>.</p>
<h3>So, how it work.</h3>
<p>Your basic structure of HTML for Carousel should be like this:-</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;div id=&quot;my_carousel&quot;&gt;
   &lt;ul&gt;
    	&lt;li&gt;some content...&lt;/li&gt;
        &lt;li&gt;some content...&lt;/li&gt;
        &lt;li&gt;some content...&lt;/li&gt;
        &lt;li&gt;some content...&lt;/li&gt;
        &lt;li&gt;some content...&lt;/li&gt;
        &lt;li&gt;some content...&lt;/li&gt;
        .....
    &lt;/ul&gt;
&lt;/div&gt;</pre></div></div>

<h3>What you need to do before applying &#8220;my_carousel&#8221; ID to your Carousel DIV.</h3>
<p>1. Put any HTML content which you want to display in your <strong>LI&#8217;s</strong>.<br />
2. Create <strong>CSS </strong>for your Carousel DIV.<br />
3. You also need two images, or button to scroll your content in left and right direction.<br />
4. Assign &#8220;<strong>btnprev</strong>&#8221; class to your left button or image.<br />
5. Assign &#8220;<strong>btnnext</strong>&#8221; class to your right button or image.<br />
6. Assign &#8220;<strong>my_carousel</strong>&#8221; ID to you Carousel DIV.</p>
<h3>How JavaScript Code work:-</h3>
<p>So, when browser load the page JavaScript look for &#8220;<strong>my_carousel</strong>&#8221; ID in HTML and apply all the require attributes and events to your DIV, UL, and LI.</p>
<h4>Important JavaScript variables and their purpose:-</h4>
<p><strong>step</strong> &#8211; How many LI&#8217;s you want to scroll on click of left and right button.<br />
<strong>current</strong> &#8211; Index or Number of left most visible LI in carousel.<br />
<strong>maximum</strong> &#8211; Total number of LI in carousel.<br />
<strong>visible</strong> &#8211; Number of visible LI&#8217;s.<br />
<strong>speed</strong> &#8211; Animation speed.<br />
<strong>liSize</strong> &#8211; Width of one LI in pixels.<br />
<strong>carousel_height</strong> &#8211; Carousel DIV height.<br />
<strong>ulSize</strong> &#8211; Width of UL. You can calculate it like this liSize * maximum.<br />
<strong>divSize</strong> &#8211; Width of CArousel DIV. You can calculate it like this liSize * visible.</p>
<h3>Assign require attributes to DIV, UL, and LI.</h3>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#my_carousel'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;width&quot;</span><span style="color: #339933;">,</span> divSize<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;px&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;height&quot;</span><span style="color: #339933;">,</span> carousel_height<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;px&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;visibility&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;visible&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;overflow&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;hidden&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;position&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;relative&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#my_carousel ul'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;width&quot;</span><span style="color: #339933;">,</span> ulSize<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;px&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;left&quot;</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span>current <span style="color: #339933;">*</span> liSize<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;position&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;absolute&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Here we changed the <strong>width, height, visibility, overflow, and position</strong> of Carousel DIV. The Carousel DIV <strong>overflow = hidden</strong> property is very important here, through it we are just showing the require(visible) LI&#8217;s which we want to show at a time. We just hide the remaining LI&#8217;s.</p>
<p>We also changes the <strong>width, left and position</strong> of UL.</p>
<h3>Assign Click event to left and right buttons/images</h3>
<h4>Left button/image</h4>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.btnprev'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>current <span style="color: #339933;">-</span> step <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">0</span> <span style="color: #339933;">||</span> current <span style="color: #339933;">-</span> step <span style="color: #339933;">&gt;</span> maximum <span style="color: #339933;">-</span> visible<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
		current <span style="color: #339933;">=</span> current <span style="color: #339933;">-</span> step<span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#my_carousel ul'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>left<span style="color: #339933;">:</span> <span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span>liSize <span style="color: #339933;">*</span> current<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> speed<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>So, we have assigned a click event on previous button. So, we are first checking the index of current LI. If the current LI is the first LI we will not do anything. We will simply return from the function. If the current LI is not the first LI then scroll the content of UL to left hand side by using the<strong> jQuery &#8220;animate&#8221; function</strong>. For more information about animate function <strong><a href="http://api.jquery.com/animate/">click here</a></strong>. And we also changed the current to current left most most visible LI.</p>
<h4>Right button/image</h4>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.btnnext'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>current <span style="color: #339933;">+</span> step <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">0</span> <span style="color: #339933;">||</span> current <span style="color: #339933;">+</span> step <span style="color: #339933;">&gt;</span> maximum <span style="color: #339933;">-</span> visible<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
		current <span style="color: #339933;">=</span> current <span style="color: #339933;">+</span> step<span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#my_carousel ul'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>left<span style="color: #339933;">:</span> <span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span>liSize <span style="color: #339933;">*</span> current<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> speed<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Similarly we assigned the clicked event on next button and followed the same logic what we used for previous click. We just changed it slightly to check last LI when we click on next button. If the current is last LI we will do nothing.</p>
<h3>Complete JavaScript Code:-</h3>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script language<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;javascript&quot;</span><span style="color: #339933;">&gt;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> step <span style="color: #339933;">=</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">;</span> 
		<span style="color: #003366; font-weight: bold;">var</span> current <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> 
		<span style="color: #003366; font-weight: bold;">var</span> maximum <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#my_carousel ul li'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		<span style="color: #003366; font-weight: bold;">var</span> visible <span style="color: #339933;">=</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">;</span> 
		<span style="color: #003366; font-weight: bold;">var</span> speed <span style="color: #339933;">=</span> <span style="color: #CC0000;">200</span><span style="color: #339933;">;</span> 
		<span style="color: #003366; font-weight: bold;">var</span> liSize <span style="color: #339933;">=</span> <span style="color: #CC0000;">331</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> carousel_height <span style="color: #339933;">=</span> <span style="color: #CC0000;">161</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
		<span style="color: #003366; font-weight: bold;">var</span> ulSize <span style="color: #339933;">=</span> liSize <span style="color: #339933;">*</span> maximum<span style="color: #339933;">;</span>   
		<span style="color: #003366; font-weight: bold;">var</span> divSize <span style="color: #339933;">=</span> liSize <span style="color: #339933;">*</span> visible<span style="color: #339933;">;</span>  
&nbsp;
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#my_carousel ul'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;width&quot;</span><span style="color: #339933;">,</span> ulSize<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;px&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;left&quot;</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span>current <span style="color: #339933;">*</span> liSize<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;position&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;absolute&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#my_carousel'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;width&quot;</span><span style="color: #339933;">,</span> divSize<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;px&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;height&quot;</span><span style="color: #339933;">,</span> carousel_height<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;px&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;visibility&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;visible&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;overflow&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;hidden&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;position&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;relative&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.btnnext'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
			<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>current <span style="color: #339933;">+</span> step <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">0</span> <span style="color: #339933;">||</span> current <span style="color: #339933;">+</span> step <span style="color: #339933;">&gt;</span> maximum <span style="color: #339933;">-</span> visible<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
			<span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
				current <span style="color: #339933;">=</span> current <span style="color: #339933;">+</span> step<span style="color: #339933;">;</span>
				$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#my_carousel ul'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>left<span style="color: #339933;">:</span> <span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span>liSize <span style="color: #339933;">*</span> current<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> speed<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.btnprev'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
			<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>current <span style="color: #339933;">-</span> step <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">0</span> <span style="color: #339933;">||</span> current <span style="color: #339933;">-</span> step <span style="color: #339933;">&gt;</span> maximum <span style="color: #339933;">-</span> visible<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
			<span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
				current <span style="color: #339933;">=</span> current <span style="color: #339933;">-</span> step<span style="color: #339933;">;</span>
				$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#my_carousel ul'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>left<span style="color: #339933;">:</span> <span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span>liSize <span style="color: #339933;">*</span> current<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> speed<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.akchauhan.com/create-simple-carousel-using-jquery/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Round Number upto 2 decimal places in JavaScript</title>
		<link>http://www.akchauhan.com/round-number-upto-2-decimal-places-in-javascript/</link>
		<comments>http://www.akchauhan.com/round-number-upto-2-decimal-places-in-javascript/#comments</comments>
		<pubDate>Sat, 16 Jan 2010 22:41:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.akchauhan.com/?p=598</guid>
		<description><![CDATA[JavaScript&#8217;s Math.round() function doesn&#8217;t provide facility to round off a number up to 2 or more decimal places. So, here I&#8217;m showing a simple JavaScript code using which you can round off numbers up to 2 decimal places. You can change this for more decimal places. var retailPrice = 9.99; var percentage = 0.2525; /* [...]]]></description>
			<content:encoded><![CDATA[<p>JavaScript&#8217;s <strong>Math.round()</strong> function doesn&#8217;t provide facility to round off a number up to 2 or more decimal places. So, here I&#8217;m showing a simple JavaScript code using which you can round off numbers up to 2 decimal places. You can change this for more decimal places.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> retailPrice <span style="color: #339933;">=</span> <span style="color: #CC0000;">9.99</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> percentage <span style="color: #339933;">=</span> <span style="color: #CC0000;">0.2525</span><span style="color: #339933;">;</span> <span style="color: #009966; font-style: italic;">/* 25.25% */</span>
<span style="color: #003366; font-weight: bold;">var</span> decimalPlace <span style="color: #339933;">=</span> <span style="color: #CC0000;">100</span><span style="color: #339933;">;</span> <span style="color: #009966; font-style: italic;">/* 100 for 2 decimal place. 1000 for 3 decimal place.*/</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> wholeSalePrice <span style="color: #339933;">=</span> Math.<span style="color: #660066;">round</span><span style="color: #009900;">&#40;</span>percentage <span style="color: #339933;">*</span> retailPrice <span style="color: #339933;">*</span> decimalPlace<span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> decimalPlace<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>wholeSalePrice<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">/* This will show 2.52 */</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.akchauhan.com/round-number-upto-2-decimal-places-in-javascript/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

