<?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 &#187; PHP</title>
	<atom:link href="http://www.akchauhan.com/category/php/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>Sun, 04 Jul 2010 20:19:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<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>0</slash:comments>
		</item>
		<item>
		<title>Create a TinyURL using PHP and TinyURL API</title>
		<link>http://www.akchauhan.com/create-a-tinyurl-using-php-and-tinyurl-api/</link>
		<comments>http://www.akchauhan.com/create-a-tinyurl-using-php-and-tinyurl-api/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 07:30:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Service]]></category>
		<category><![CDATA[TinyUrl]]></category>

		<guid isPermaLink="false">http://www.akchauhan.com/?p=591</guid>
		<description><![CDATA[TinyURL is an awesome service. For those who don&#8217;t know what TinyURL is, TinyURL allows you to convert your long URLs like &#8220;http://www.akchauhan.com/category/jquery/&#8221; to small URLs like &#8220;http://tinyurl.com/yz4c4ba&#8221;. Basically you need such type of service when you are posting your data to some third party web service and there is limit on the number of [...]]]></description>
			<content:encoded><![CDATA[<p><strong>TinyURL </strong>is an awesome service. For those who don&#8217;t know what <strong>TinyURL </strong>is, <strong>TinyURL </strong>allows you to convert your long URLs like <strong>&#8220;http://www.akchauhan.com/category/jquery/&#8221;</strong> to small URLs like <strong>&#8220;http://tinyurl.com/yz4c4ba&#8221;</strong>. Basically you need such type of service when you are posting your data to some third party web service and there is limit on the number of characters you can post like <strong>Twitter</strong>. Twitter only allow 140 characters long Tweet.</p>
<p>Using the PHP and TinyURL API, you can create these tiny URLs.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> get_tiny_url<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</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>  
	<span style="color: #000088;">$timeout</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</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_URL<span style="color: #339933;">,</span><span style="color: #0000ff;">'http://tinyurl.com/api-create.php?url='</span><span style="color: #339933;">.</span><span style="color: #000088;">$url</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: #cc66cc;">1</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_CONNECTTIMEOUT<span style="color: #339933;">,</span><span style="color: #000088;">$timeout</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
	<span style="color: #000088;">$data</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>  
	<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;">$data</span><span style="color: #339933;">;</span>  
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//test it out!</span>
<span style="color: #000088;">$new_url</span> <span style="color: #339933;">=</span> get_tiny_url<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://www.akchauhan.com/category/jquery/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//returns http://tinyurl.com/yz4c4ba</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$new_url</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.akchauhan.com/create-a-tinyurl-using-php-and-tinyurl-api/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Create Random Alphanumeric Password in PHP</title>
		<link>http://www.akchauhan.com/create-random-alphanumeric-password-in-php/</link>
		<comments>http://www.akchauhan.com/create-random-alphanumeric-password-in-php/#comments</comments>
		<pubDate>Thu, 12 Nov 2009 08:16:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Password]]></category>

		<guid isPermaLink="false">http://www.akchauhan.com/?p=585</guid>
		<description><![CDATA[We can use this simple password generation function to create random passwords. The maximum limit of generated password is 36 characters. &#60;?php function gen_password&#40;$size = 8&#41; &#123; $size = $size &#62; 36 ? 30 : $size; $pool = array_merge&#40;range&#40;0, 9&#41;, range&#40;'A', 'Z'&#41;&#41;; $rand_keys = array_rand&#40;$pool, $size&#41;; &#160; $password = ''; &#160; foreach &#40;$rand_keys as $key&#41; [...]]]></description>
			<content:encoded><![CDATA[<p>We can use this simple password generation function to create random passwords. The maximum limit of generated password is 36 characters.</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> gen_password<span style="color: #009900;">&#40;</span><span style="color: #000088;">$size</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">8</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$size</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$size</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">36</span> ? <span style="color: #cc66cc;">30</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$size</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$pool</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_merge</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">range</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">9</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">range</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'A'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Z'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$rand_keys</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_rand</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pool</span><span style="color: #339933;">,</span> <span style="color: #000088;">$size</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$rand_keys</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$password</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$pool</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</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: #000088;">$password</span> <span style="color: #339933;">=</span> gen_password<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: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>We can use it like this.</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;">$password</span> <span style="color: #339933;">=</span> gen_password<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: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.akchauhan.com/create-random-alphanumeric-password-in-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Create Windows Service to Schedule PHP Script execution</title>
		<link>http://www.akchauhan.com/create-windows-service-to-schedule-php-script-execution/</link>
		<comments>http://www.akchauhan.com/create-windows-service-to-schedule-php-script-execution/#comments</comments>
		<pubDate>Tue, 22 Sep 2009 15:02:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Service]]></category>
		<category><![CDATA[Job Schedule]]></category>
		<category><![CDATA[Windows Service]]></category>

		<guid isPermaLink="false">http://www.akchauhan.com/?p=560</guid>
		<description><![CDATA[If you want to schedule your PHP script or any other command on Windows Platform recursively after a fix interval of time then you can create a Windows Service for it. Windows service is very easy to create in Visual Studio.Net. I&#8217;m using C# language for this scheduler service you can also use VB.net for [...]]]></description>
			<content:encoded><![CDATA[<p>If you want to schedule your PHP script or any other command on <strong>Windows Platform</strong> recursively after a fix interval of time then you can create a <strong>Windows Service</strong> for it. Windows service is very easy to create in Visual Studio.Net. I&#8217;m using <strong>C#</strong> language for this scheduler service you can also use <strong>VB.net</strong> for it. Basically we need this type of service if we want to execute some PHP script in background in a specific interval of time. For example, If you want to import data in bulk from some web service.</p>
<p>You need to follow these steps: -</p>
<ul>
<li>
Create a project by using the Windows Service application template. This template creates a class for you that inherits from ServiceBase and writes much of the basic service code, such as the code to start the service.</li>
<li>
Write the code for the OnStart and OnStop procedures, and override any other methods that you want to redefine.
</li>
<li>
Add the necessary installers for your service application. By default, a class that contains two or more installers is added to your application when you click the Add Installer link: one to install the process, and one for each associated service that your project contains.
</li>
<li>
Build your project.
</li>
<li>
Create a setup project to install your service, and then install it.
</li>
<li>
Access the Windows 2000 Services Control Manager and start your service.
</li>
</ul>
<p>For more detail check &#8220;<strong>Walkthrough: Creating a Windows Service Application in the Component Designer</strong>&#8221; topic in <strong>MSDN</strong>.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">using <span style="color: #990000;">System</span><span style="color: #339933;">;</span>
using <span style="color: #990000;">System</span><span style="color: #339933;">.</span>Collections<span style="color: #339933;">.</span>Generic<span style="color: #339933;">;</span>
using <span style="color: #990000;">System</span><span style="color: #339933;">.</span>ComponentModel<span style="color: #339933;">;</span>
using <span style="color: #990000;">System</span><span style="color: #339933;">.</span>Data<span style="color: #339933;">;</span>
using <span style="color: #990000;">System</span><span style="color: #339933;">.</span>Diagnostics<span style="color: #339933;">;</span>
using <span style="color: #990000;">System</span><span style="color: #339933;">.</span>Linq<span style="color: #339933;">;</span>
using <span style="color: #990000;">System</span><span style="color: #339933;">.</span>ServiceProcess<span style="color: #339933;">;</span>
using <span style="color: #990000;">System</span><span style="color: #339933;">.</span>Text<span style="color: #339933;">;</span>
using <span style="color: #990000;">System</span><span style="color: #339933;">.</span>Timers<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">namespace</span> MyNewService
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> partial <span style="color: #000000; font-weight: bold;">class</span> MyNewService <span style="color: #339933;">:</span> ServiceBase
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">private</span> Timer syncTimer <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>  
&nbsp;
        <span style="color: #000000; font-weight: bold;">public</span> MyNewService<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            InitializeComponent<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        protected override void OnStart<span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            syncTimer <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Timer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            this<span style="color: #339933;">.</span>syncTimer<span style="color: #339933;">.</span>Interval <span style="color: #339933;">=</span> <span style="color: #cc66cc;">180000</span><span style="color: #339933;">;</span>
            this<span style="color: #339933;">.</span>syncTimer<span style="color: #339933;">.</span>Elapsed <span style="color: #339933;">+=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #990000;">System</span><span style="color: #339933;">.</span>Timers<span style="color: #339933;">.</span>ElapsedEventHandler<span style="color: #009900;">&#40;</span>this<span style="color: #339933;">.</span>syncTimer_Tick<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            syncTimer<span style="color: #339933;">.</span>Enabled <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        protected override void OnStop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            syncTimer<span style="color: #339933;">.</span>Enabled <span style="color: #339933;">=</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: #000000; font-weight: bold;">private</span> void syncTimer_Tick<span style="color: #009900;">&#40;</span>object sender<span style="color: #339933;">,</span> EventArgs e<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #990000;">System</span><span style="color: #339933;">.</span>Diagnostics<span style="color: #339933;">.</span>Process<span style="color: #339933;">.</span>Start<span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #0000ff;">&quot;C:<span style="color: #660099; font-weight: bold;">\xa</span>mpp\htdocs<span style="color: #000099; font-weight: bold;">\t</span>ask.bat&quot;</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></pre></div></div>

<p>The <strong>task.bat</strong> file is a batch file. We are executing our PHP script through this batch file. First we set the path of directory where php.exe is located in your windows. The <strong>import.php</strong> is basically importing data in bulk from some web and we need to execute this script file background in every 3 minutes.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">@</span><span style="color: #b1b100;">echo</span> off
cd\
set path<span style="color: #339933;">=</span>C<span style="color: #339933;">:</span>\xampp\php<span style="color: #339933;">;</span>
cd <span style="color: #0000ff;">&quot;C:<span style="color: #660099; font-weight: bold;">\xa</span>mpp\htdocs&quot;</span>
php import<span style="color: #339933;">.</span>php
<span style="color: #990000;">exit</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.akchauhan.com/create-windows-service-to-schedule-php-script-execution/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How use cURL library when running PHP through Command Line</title>
		<link>http://www.akchauhan.com/how-use-curl-library-when-running-php-through-command-line/</link>
		<comments>http://www.akchauhan.com/how-use-curl-library-when-running-php-through-command-line/#comments</comments>
		<pubDate>Wed, 16 Sep 2009 23:40:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[curl]]></category>

		<guid isPermaLink="false">http://www.akchauhan.com/?p=551</guid>
		<description><![CDATA[If you run any PHP code which using cURL extension through command line like this: c:\&#62;php somefile.php it might give error that &#8220;curl_init()&#8221; function is not defined. The reason is the cURL extension &#8220;php_curl.dll&#8221; is not loaded. So, to resolve this issue you can load cURL (or any extension) dynamically in your PHP code. The [...]]]></description>
			<content:encoded><![CDATA[<p>If you run any <strong>PHP code</strong> which using <strong>cURL extension</strong> through command line like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">c<span style="color: #339933;">:</span>\<span style="color: #339933;">&gt;</span>php somefile<span style="color: #339933;">.</span>php</pre></div></div>

<p> it might give error that &#8220;<strong>curl_init()</strong>&#8221; function is not defined. The reason is the cURL extension &#8220;<strong>php_curl.dll</strong>&#8221; is not loaded. So, to resolve this issue you can load cURL (or any extension) dynamically in your PHP code. The &#8220;<strong>dl()</strong>&#8221; basically load PHP extension at <strong>runtime</strong>.</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: #990000;">dl</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;php_curl.dll&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">...</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.akchauhan.com/how-use-curl-library-when-running-php-through-command-line/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create Web Services using AMFPHP and XML-RPC</title>
		<link>http://www.akchauhan.com/create-web-services-using-amfphp-and-xml-rpc/</link>
		<comments>http://www.akchauhan.com/create-web-services-using-amfphp-and-xml-rpc/#comments</comments>
		<pubDate>Tue, 18 Aug 2009 14:23:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Web Service]]></category>
		<category><![CDATA[AMFPHP]]></category>
		<category><![CDATA[XMLRPC]]></category>

		<guid isPermaLink="false">http://www.akchauhan.com/?p=485</guid>
		<description><![CDATA[Here I&#8217;m going to demonstrate how we can create web services using AMFPHP and access them using XML-RPC. First, let&#8217;s understand some important terms:- AMFPHP: AMFPHP is a free open-source PHP implementation of the Action Message Format(AMF). AMF allows for binary serialization of Action Script (AS2, AS3) native types and objects to be sent to [...]]]></description>
			<content:encoded><![CDATA[<p>Here I&#8217;m going to demonstrate how we can create web services using AMFPHP and access them using XML-RPC. First, let&#8217;s understand some important terms:-</br></p>
<p><strong>AMFPHP: </strong> AMFPHP is a free open-source PHP implementation of the Action Message Format(AMF). AMF allows for binary serialization of Action Script (AS2, AS3) native types and objects to be sent to server side services. You can learn more about AMFPHP from its official website <a href="http://www.amfphp.org">www.amfphp.org</a>.</br></br></p>
<p><strong>XML-RPC: </strong>It&#8217;s a specification and a set of implementations that allow software running on disparate operating systems, running in different environments to make procedure calls over the Internet. You can learn more about AMFPHP from its official website <a href="http://www.xmlrpc.com/">www.xmlrpc.com</a>.</br></br></p>
<p>So, here we are creating web services for FLEX or FLASH which we can directly call using the XML-RPC because AMFPHP already included the batteries for XML-RPC and JSON. We don&#8217;t need to do any thing special for accessing same services using XML-RPC.</br></br></p>
<p>First, we need to download AMFPHP. You can download the latest version of from <a href="http://sourceforge.net/projects/amfphp/files/#files">here</a>.</br> Unzip the files and place them into your htdocs directory. You can visit <strong>http://localhost/amfphp/gateway.php</strong> URL in your local to check the AMFPHP is properly installed or not.</p>
<p><strong>1. How to create web service using AMFPHP</strong><br />
In AMFPHP, all files related to web services should be places inside <strong>&#8220;amfphp\services&#8221;</strong> directory. I&#8217;m considering here an example of &#8220;Order&#8221; Web Service to make understand it easily.</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: #009933; font-style: italic;">/**
 * This class provide methods for handling orders received through web
 */</span>
<span style="color: #000000; font-weight: bold;">class</span> WebOrders <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">function</span> _getStoreInfo<span style="color: #009900;">&#40;</span><span style="color: #000088;">$storeid</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$query_id</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM store WHERE storeid = '<span style="color: #006699; font-weight: bold;">$storeid</span>' AND status = 1&quot;</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;">mysql_num_rows</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query_id</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</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: #990000;">mysql_fetch_object</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query_id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
     * Method to receive new order from web.
     * @returns order request id. In case of error return error message.
     */</span>
    <span style="color: #000000; font-weight: bold;">function</span> receiveNewOrder<span style="color: #009900;">&#40;</span><span style="color: #000088;">$order</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$store_info</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_getStoreInfo<span style="color: #009900;">&#40;</span><span style="color: #000088;">$order</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'storeid'</span><span style="color: #009900;">&#93;</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: #000088;">$store_info</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">'Invalid store ID.'</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT MAX(fld_order_id) AS fld_order_id FROM tbl_order&quot;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$query_id</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$obj</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_object</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query_id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$next_fld_order_id</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</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;">$obj</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fld_order_id</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$next_fld_order_id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$obj</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fld_order_id</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
                <span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;INSERT INTO tbl_order(fld_order_id, fld_total, fld_tax, fld_customer_name, fld_phone, fld_address, 
				fld_email_id, fld_del_status, fld_comment_cust, fld_order_status, fld_request_time, fld_lastupdated)
				VALUES('<span style="color: #006699; font-weight: bold;">$next_fld_order_id</span>', '<span style="color: #006699; font-weight: bold;">{$order['total']}</span>', '<span style="color: #006699; font-weight: bold;">{$order['tax']}</span>', '<span style="color: #006699; font-weight: bold;">{$order['customer_name']}</span>', '<span style="color: #006699; font-weight: bold;">{$order['phone']}</span>', 
				'<span style="color: #006699; font-weight: bold;">{$order['address']}</span>', '<span style="color: #006699; font-weight: bold;">{$order['email']}</span>', '<span style="color: #006699; font-weight: bold;">{$order['delivery']}</span>', '<span style="color: #006699; font-weight: bold;">{$order['note']}</span>', '1', NOW(), NOW())&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$query_id</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$order</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'products'</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$product</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;INSERT INTO tbl_order_detail(fld_order_id, fld_pid, fld_qty, fld_uid, fld_price, fld_lastupdated)
					VALUES('<span style="color: #006699; font-weight: bold;">$next_fld_order_id</span>', '<span style="color: #006699; font-weight: bold;">{$product['productid']}</span>', '<span style="color: #006699; font-weight: bold;">{$product['qty']}</span>', '<span style="color: #006699; font-weight: bold;">{$product['unit']}</span>', 
					'<span style="color: #006699; font-weight: bold;">{$product['price']}</span>', NOW())&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$query_id</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</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;">$next_fld_order_id</span><span style="color: #339933;">;</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>Here we have created a class <strong>&#8220;WebOrders&#8221;</strong>. It&#8217;s having two methods <strong>&#8220;_getStoreInfo&#8221;</strong> and <strong>&#8220;receiveNewOrder&#8221;</strong>. <strong>&#8220;_getStoreInfo&#8221;</strong> is the private method (We can create private method by prefixing &#8216;_&#8217; before function name). Its means no one can access this method of dervice. <strong>&#8220;receiveNewOrder&#8221;</strong> method is for receiving the new order request. Its taking <strong>&#8220;$order&#8221;</strong> associative array as paramater and return the new order ID.</p>
<p><strong>2. Access it using XML-RPC</strong><br />
We have create a web Service, now we need to access ir using XML-RPC. We need a XML-RPC library for calling the web service. I&#8217;m using this one <strong><a href="http://phpxmlrpc.sourceforge.net/#download">http://phpxmlrpc.sourceforge.net/#download</a></strong>. You can call the web service like this:-</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: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'lib/xmlrpc.inc'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  	<span style="color: #000088;">$xmlrpc_client</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> xmlrpc_client<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/amfphp/xmlrpc.php&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'localhost'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">80</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  	<span style="color: #000088;">$xmlrpc_client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setDebug</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//this will print all the responses as they come back</span>
&nbsp;
  	<span style="color: #000088;">$order</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> stdClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  	<span style="color: #000088;">$order</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">storeid</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$order</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">total</span> <span style="color: #339933;">=</span> <span style="color:#800080;">100.50</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$order</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">tax</span> <span style="color: #339933;">=</span> <span style="color:#800080;">10.50</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$order</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">customer_name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Anil Chauhan'</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$order</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">email</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'meetanilchauhan@varshyl.com'</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$order</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">phone</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'9810713123'</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$order</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">address</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'24 - Laxmi Nagar, Delhi'</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$order</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">delivery</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'1'</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$order</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">note</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Test Note'</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$order</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">products</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'productid'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">25</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'qty'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'unit'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'2'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'price'</span> <span style="color: #339933;">=&gt;</span> <span style="color:#800080;">30.00</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  	<span style="color: #000088;">$order</span> <span style="color: #339933;">=</span> php_xmlrpc_encode<span style="color: #009900;">&#40;</span><span style="color: #000088;">$order</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  	<span style="color: #000088;">$xmlrpc_message</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> xmlrpcmsg<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;WebOrders.receiveNewOrder&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$order</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  	<span style="color: #000088;">$xmlrpc_response</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$xmlrpc_client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">send</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xmlrpc_message</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: #000088;">$xmlrpc_response</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">faultCode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  		<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$xmlrpc_response</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">faultString</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: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
  		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Pingback successful&quot;</span><span style="color: #339933;">;</span>
  	<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Here, first we have included the <strong>&#8220;xmlrpc.inc&#8221;</strong> lilbrary. Then we have created the object of <strong>xmlrpc_client</strong>. We have also enabled the debug option using &#8220;$xmlrpc_client->setDebug(1);&#8221;. Make sure you switch off the debugging option on your production server.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.akchauhan.com/create-web-services-using-amfphp-and-xml-rpc/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Convert XML to Array using DOM extension in PHP5</title>
		<link>http://www.akchauhan.com/convert-xml-to-array-using-dom-extension-in-php5/</link>
		<comments>http://www.akchauhan.com/convert-xml-to-array-using-dom-extension-in-php5/#comments</comments>
		<pubDate>Sat, 04 Jul 2009 10:40:53 +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=464</guid>
		<description><![CDATA[The xml2array class convert the XML stored in a string into an ARRAY. We are using the DOM extension of PHP5. The DOM extension replaced the DOM XML extension available in PHP4. The DOM XML extension is depreciated in PHP5. &#60;?php class xml2array &#123; &#160; function xml2array&#40;$xml&#41; &#123; if &#40;is_string&#40;$xml&#41;&#41; &#123; $this-&#62;dom = new DOMDocument; [...]]]></description>
			<content:encoded><![CDATA[<p>The <strong>xml2array</strong> class convert the <strong>XML</strong> stored in a string into an <strong>ARRAY</strong>. We are using the <strong>DOM extension</strong> of <strong>PHP5</strong>. The <strong>DOM </strong>extension replaced the <strong>DOM XML</strong> extension available in <strong>PHP4</strong>. The DOM XML extension is depreciated in PHP5.</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> xml2array <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> xml2array<span style="color: #009900;">&#40;</span><span style="color: #000088;">$xml</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;">$xml</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;">dom</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DOMDocument<span style="color: #339933;">;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dom</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">loadXml</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xml</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: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> _process<span style="color: #009900;">&#40;</span><span style="color: #000088;">$node</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
		<span style="color: #000088;">$occurance</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">childNodes</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$child</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$occurance</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$child</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeName</span><span style="color: #009900;">&#93;</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: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeType</span> <span style="color: #339933;">==</span> XML_TEXT_NODE<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
			<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">html_entity_decode</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">htmlentities</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeValue</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">ENT_COMPAT</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'UTF-8'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> 
                                     <span style="color: #009900; font-weight: bold;">ENT_COMPAT</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'ISO-8859-15'</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: #009900;">&#123;</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hasChildNodes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$children</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">childNodes</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span><span style="color: #000088;">$children</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">length</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #000088;">$child</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$children</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</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: #000088;">$child</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeName</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'#text'</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: #000088;">$occurance</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$child</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeName</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
							<span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$child</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeName</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_process<span style="color: #009900;">&#40;</span><span style="color: #000088;">$child</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: #009900;">&#123;</span>
							<span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$child</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeName</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_process<span style="color: #009900;">&#40;</span><span style="color: #000088;">$child</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: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$child</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeName</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'#text'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
						<span style="color: #000088;">$text</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_process<span style="color: #009900;">&#40;</span><span style="color: #000088;">$child</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;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
							<span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$child</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeName</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_process<span style="color: #009900;">&#40;</span><span style="color: #000088;">$child</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> 
&nbsp;
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hasAttributes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
				<span style="color: #000088;">$attributes</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">attributes</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;">$attributes</span><span style="color: #009900;">&#41;</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;">$attributes</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$attr</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
						<span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;@&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$attr</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$attr</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">value</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>
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$result</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> getResult<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_process<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dom</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: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>We can use this class like this.</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> xml2array<span style="color: #009900;">&#40;</span><span style="color: #000088;">$XML_string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$XML_array</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$obj</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getResult</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.akchauhan.com/convert-xml-to-array-using-dom-extension-in-php5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create Drupal form using theme_table() like module list form (Part II)</title>
		<link>http://www.akchauhan.com/create-drupal-form-using-theme_table-like-module-list-form-part-ii/</link>
		<comments>http://www.akchauhan.com/create-drupal-form-using-theme_table-like-module-list-form-part-ii/#comments</comments>
		<pubDate>Sat, 27 Jun 2009 13:12:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Drupal]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Form]]></category>

		<guid isPermaLink="false">http://www.akchauhan.com/?p=452</guid>
		<description><![CDATA[This post is the second part of Create Drupal form using theme_table() like module list form post. In first part I have showed how we can create Drupal form like we have in Module list pages. In this post, I am showing how we disable some of the checkboxes so user can&#8217;t select them like [...]]]></description>
			<content:encoded><![CDATA[<p>This post is the second part of <a href="http://www.akchauhan.com/create-drupal-form-using-theme_table-like-module-list-form/" target="_blank"><strong>Create Drupal form using theme_table() like module list form</strong></a> post. In first part I have showed how we can create Drupal form like we have in Module list pages. In this post, I am showing how we disable some of the checkboxes so user can&#8217;t select them like we have for core modules in module list page. We can&#8217;t enable/disable core modules in module list.<br />
<div id="attachment_453" class="wp-caption aligncenter" style="width: 860px"><img src="http://www.akchauhan.com/wp-content/uploads/2009/06/orders.jpg" alt="Drupal Form using theme_table() function (Part II)" title="Drupal Form using theme_table() function (Part II)" width="850" height="220" class="size-full wp-image-453" /><p class="wp-caption-text">Drupal Form using theme_table() function (Part II)</p></div></p>
<p>Here I am just showing the changes which we require in code of Part I post.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"> <span style="color: #000088;">$form</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'featured'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'#type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'checkboxes'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'#options'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$options</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'#default_value'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$status</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Change this to </span>
&nbsp;
<span style="color: #000088;">$form</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'featured'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'#type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'checkboxes'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'#options'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$options</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'#default_value'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$status</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'#process'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">'expand_checkboxes'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'featured_disable'</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'#disabled_products'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$disabled</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>In above code &#8220;<strong>$disabled</strong>&#8221; is an array containing the <strong>productid&#8217;s</strong> of all the products which we want to show as checked and in disable state. The structure of &#8220;<strong>$disabled</strong>&#8221; array is similar to <strong>&#8220;$status&#8221;</strong> array. We stored this array in <strong>&#8220;#disabled_products&#8221;</strong>. We also added <strong>&#8220;#process&#8221;</strong> in above code. </p>
<p><strong>&#8220;expand_checkboxes&#8221;</strong> and <strong>&#8220;featured_disable&#8221;</strong> are function names which Drupal call when create and render these checkboxes. <strong>&#8220;expand_checkboxes()&#8221;</strong> is defined in Drupal core files and we don&#8217;t need to define it again.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> featured_disable<span style="color: #009900;">&#40;</span><span style="color: #000088;">$form</span><span style="color: #339933;">,</span> <span style="color: #000088;">$edit</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;">$form</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'#disabled_products'</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  		<span style="color: #000088;">$form</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'#attributes'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'disabled'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'disabled'</span><span style="color: #339933;">;</span>
  	<span style="color: #009900;">&#125;</span>
&nbsp;
  	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$form</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>&#8220;featured_disable()&#8221;</strong> function is very important here. Drupal call this function when renders these checkboxes. Here we assigned <strong>&#8220;disabled&#8221;</strong> attribute to each checkbox which we want as disable.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.akchauhan.com/create-drupal-form-using-theme_table-like-module-list-form-part-ii/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How use AJAX in DRUPAL</title>
		<link>http://www.akchauhan.com/how-use-ajax-in-drupal/</link>
		<comments>http://www.akchauhan.com/how-use-ajax-in-drupal/#comments</comments>
		<pubDate>Mon, 22 Jun 2009 04:26:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Drupal]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.akchauhan.com/?p=442</guid>
		<description><![CDATA[We can easily use AJAX in DRUPAL framework. Drupal provide the jQuery javascript library so we can use jQuery for our AJAX implementation. First we write a module in which we are going to implement the server side logic. Suppose our module name is product and we will check the given product name is exist [...]]]></description>
			<content:encoded><![CDATA[<p><div id="attachment_393" class="wp-caption aligncenter" style="width: 403px"><img src="http://www.akchauhan.com/wp-content/uploads/2009/06/drupal-ajax.jpg" alt="How use AJAX in DRUPAL" title="How use AJAX in DRUPAL" width="393" height="198" class="aligncenter size-full wp-image-445" /><p class="wp-caption-text">How use AJAX in DRUPAL</p></div><br />
We can easily use AJAX in DRUPAL framework. Drupal provide the jQuery javascript library so we can use jQuery for our AJAX implementation. First we write a module in which we are going to implement the server side logic. Suppose our module name is product and we will check the given product name is exist or not in our product table.</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;">/*product.module*/</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> product_menu<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  	<span style="color: #000088;">$items</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$items</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'product'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'page callback'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'drupal_get_form'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'page arguments'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'product'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    		<span style="color: #0000ff;">'access arguments'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">,</span>
    		<span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> MENU_CALLBACK<span style="color: #339933;">,</span>
  	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  	<span style="color: #000088;">$items</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'product/check_name'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    		<span style="color: #0000ff;">'page callback'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'check_name'</span><span style="color: #339933;">,</span>
    		<span style="color: #0000ff;">'access arguments'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">,</span>
    		<span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> MENU_CALLBACK<span style="color: #339933;">,</span>
  	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$items</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> product<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$path</span> <span style="color: #339933;">=</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;">'product'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	drupal_add_js<span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/product.js'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'module'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$form</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'product_name'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'#title'</span> <span style="color: #339933;">=&gt;</span> t<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Product Name'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'#type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'textfield'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'#required'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'#size'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">30</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'#description'</span> <span style="color: #339933;">=&gt;</span> t<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Please enter product name.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$form</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'check_name'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'#type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'markup'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'#value'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;&lt;a href='#' id='check_name'&gt;&quot;</span> <span style="color: #339933;">.</span> t<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Check Product Name'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;/a&gt;&lt;br/&gt;&quot;</span><span style="color: #339933;">,</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
	<span style="color: #000088;">$form</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'status'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'#type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'markup'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'#value'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;&lt;span id='status'&gt;&lt;/span&gt;&lt;br/&gt;&quot;</span><span style="color: #339933;">,</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
	<span style="color: #000088;">$form</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'submit'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'#type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'submit'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'#value'</span> <span style="color: #339933;">=&gt;</span> t<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Submit'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$form</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cancel'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'#type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'markup'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'#value'</span> <span style="color: #339933;">=&gt;</span> l<span style="color: #009900;">&#40;</span>t<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Cancel'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'product_mgmt'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$form</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> check_name<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT COUNT(*) AS total FROM {product} WHERE LOWER(product_name) LIKE ('<span style="color: #009933; font-weight: bold;">%s</span>')&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$rs</span> <span style="color: #339933;">=</span> db_query<span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #339933;">,</span> <span style="color: #000088;">$name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$info</span> <span style="color: #339933;">=</span> db_fetch_object<span style="color: #009900;">&#40;</span><span style="color: #000088;">$rs</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$total</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$info</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">total</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$total</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;$('#status').html('This product is available.');&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;$('#status').html('This product is not available.');&quot;</span><span style="color: #339933;">;</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>Don&#8217;t return anything in &#8220;<strong>check_name()</strong>&#8221; function otherwise it will return the whole page when we access &#8220;<strong>product/check_name</strong>&#8221; path through AJAX.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/*product.js*/</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// JavaScript Document</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;">'#check_name'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'href'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'javascript:void(0);'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#edit-product-name'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">keydown</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#status'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">''</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>
&nbsp;
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#check_name'</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: #003366; font-weight: bold;">var</span> <span style="color: #000066;">name</span> <span style="color: #339933;">=</span> $.<span style="color: #660066;">trim</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#edit-product-name'</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: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">name</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#status'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Please enter product name.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		$.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
   			type<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;GET&quot;</span><span style="color: #339933;">,</span>
			url<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;/product/check_name&quot;</span><span style="color: #339933;">,</span>
   			data<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;name=&quot;</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">encodeURI</span><span style="color: #009900;">&#40;</span><span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
   			success<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>msg<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #000066; font-weight: bold;">eval</span><span style="color: #009900;">&#40;</span>msg<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;">&#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></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.akchauhan.com/how-use-ajax-in-drupal/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>
