<?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>Roshan Bhattarai's Blog -  A blog about PHP, Ajax, JavaScript, CSS and Web 2.0 &#187; php</title>
	<atom:link href="http://roshanbh.com.np/category/php/feed" rel="self" type="application/rss+xml" />
	<link>http://roshanbh.com.np</link>
	<description>Useful Tutorials, Scripts , Tips, and Resources for all PHP and Ajax beginners and experts .</description>
	<lastBuildDate>Thu, 10 Jun 2010 11:38:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>CodeIgniter : A recommendation for PHP Programmer</title>
		<link>http://roshanbh.com.np/2008/12/codeigniter-programmer-php.html</link>
		<comments>http://roshanbh.com.np/2008/12/codeigniter-programmer-php.html#comments</comments>
		<pubDate>Thu, 11 Dec 2008 19:12:25 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[coding technique]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[cakephp]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=324</guid>
		<description><![CDATA[I was thinking to publish this post way before but between my irregularity and busy schedule I couldn&#8217;t do that. Today, I would like to tell you that Why I choose CodeIgniter for my current project and recommend it for other programmers? I&#8217;ve used CakePHP for my one previous project in which I&#8217;ve used the [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F12%2Fcodeigniter-programmer-php.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F12%2Fcodeigniter-programmer-php.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p style="text-align: justify;">I was thinking to publish this post way before but between my irregularity and busy schedule I couldn&#8217;t do that. Today, I would like to tell you that Why I choose CodeIgniter for my current project and recommend it for other programmers? I&#8217;ve used CakePHP for my one previous project in which I&#8217;ve used the version 1.1.7 of Cake. I must admit that CakePHP is a great MVC framework with but there are many performance issues in the related to CakePHP and I decided not to use it until the final version of 1.2.0 of CakePHP which is still in RC phase while writing this post.</p>
<p><span id="more-324"></span></p>
<h4>Why I recommend PHP Programmers to use CodeIgniter?</h4>
<p style="text-align: justify;">Yes I&#8217;ve decided to use it along with this I&#8217;ve asked my programmer friends out there in office to use it. You&#8217;re wondering why I choose CodeIgniter rather than using Zend Framework, which  add more values in PHP programmer&#8217;s career.Let&#8217; me answer them all in the reasons below.</p>
<ol>
<li>The main issue which I got attracted with CodeIgniter is its performance. CodeIgniter is faster than other popular PHP MVC frameworks. Take a look at these Benchmark test done by <a href="http://en.wikipedia.org/wiki/Rasmus_Lerdorf" target="_blank">Rasmus Lerdorf</a>(creator of PHP programming), <a href="http://talks.php.net/show/froscon08/25">here</a> , <a href="http://talks.php.net/show/froscon08/29">here</a> in <a href="http://talks.php.net/show/froscon08/25">here</a>. And also take a look at <a href="http://www.avnetlabs.com/php/php-framework-comparison-benchmarks">another benchmark test</a> . So it&#8217;s clear that CI is faster than other Framework. Rasmus also told that he liked <a href="http://codeigniter.com/">CodeIgniter</a> because it is faster, lighter and the least like a framework.</li>
<li>Another main reason behind recommendation, it has very low learning curve. CodeIgniter Downloads come with a tremendous user guide which is  a great documentation like PHP Manual to begin with. And from my personal experience, CodeIgniter has very low learning curve compared to CakePHP and Zend Framework. If you&#8217;re a beginner for PHP frameworks then I recommend to go with CodeIgniter at begining.</li>
<li>The coding conventions are flexible and simple. Ironically, CakePHP has very strict coding conventions so you must be very careful about cases of characters while coding.</li>
<li>Why not Zend Framework and why CodeIgniter? Ok, one question goes here what is so good about Zend Framwork ? Eventual answer is ZF contain huge set of libraries and classes compared to any other framework. OK I agree, but another great news is that You can use <a href="http://www.4webby.com/freakauth/tutorials/using-zend-framework-components-in-code-igniter" target="_blank">Zend Framework&#8217;s classes in the CodeIgniter </a>using hooks in CI. So you can use huge amount of Zend&#8217;s libraried in CI as well.</li>
</ol>
<p style="text-align: justify;">These are the main reason why I recommend for using CodeIgniter for PHP programmers.But I still believe that I&#8217;ll be using CakePHP for once I get final version of 1.2.0 because I still believe that it is robust,  has a  great design patters and great tool for group development .</p>
<p>If you recommend any other PHP framework, please let us know why you recomment that framework.</p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=324&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/12/codeigniter-programmer-php.html/feed</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>How did I reduce CPU overhead problem caused by MySql?</title>
		<link>http://roshanbh.com.np/2008/12/reduce-cpu-overhead-problem-by-mysql.html</link>
		<comments>http://roshanbh.com.np/2008/12/reduce-cpu-overhead-problem-by-mysql.html#comments</comments>
		<pubDate>Tue, 02 Dec 2008 17:58:22 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[coding technique]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=320</guid>
		<description><![CDATA[From last day, We were having problem with a project which was shut down in the middle due to heavy traffic. As a technical manager, I was the person who to take charge over the project bring it down to the track. After doing few benchmark test, I came to know that the MySql access [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F12%2Freduce-cpu-overhead-problem-by-mysql.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F12%2Freduce-cpu-overhead-problem-by-mysql.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>From last day, We were having problem with a project which was shut down in the middle due to heavy traffic. As a technical manager, I was the person who to take charge over the project bring it down to the track. After doing few benchmark test, I came to know that the MySql access from a PHP file was creating the overhead to the CPU of the server.<br />
<span id="more-320"></span></p>
<h4>Problem of CPU Overhead with MySql</h4>
<p>Let me explain the problem clearly first,</p>
<p style="text-align: justify;">We&#8217;re working on a website which was similar to <a rel="nofollow" href="http://www.swoopo.co.uk/" target="_blank">http://www.swoopo.co.uk/</a> and as you can see clearly in that website the most recent data should be fetched form MySql database in each second. in the PHP page, which was being called from Ajax every second, had around 5 SQL queries to retrieve data from server.</p>
<p>First of all, I optimized that page reducing the 5 queries into single query by using left outer joins among 3 tables. And then, I did benchmark test by using <a href="http://httpd.apache.org/docs/2.0/programs/ab.html" target="_blank">Apache benchmark tool</a>(ab) 50 request with concurrency of 50 with the following command.</p>
<blockquote><p><span style="color: #993300;">ab -n 50 -c 50 http://xyz.com/ajax_page.php</span></p></blockquote>
<p>And then in another SSH shell prompt, I run the <a href="http://linux.about.com/od/commands/l/blcmdl1_top.htm">top</a> command to view the CPU usages parallelly.</p>
<p>I was still horrified that the CPU usages by mysql after 50 concurrent user was going out of control(100%) despite of optimized query. But many joins have been used in that single query and lots of data were there in those tables so the database overhead was high even though it was a single query.</p>
<h4>How did I reduced the CPU overload drastically caused by MySql?</h4>
<p>Now, the first challenge was to reduce the database access. It was clear that it was caused by concurrent database overhead in the PHP page which was being called in every second. Here is the simple steps what I did to reduce the database overhead.</p>
<ol>
<li>I created another PHP file in which I&#8217;ve transferred the mysql query causing CPU overhead and called it from Cronjob.</li>
<li>Created a temporary table for storing the output given by  PHP page called from CronJob.</li>
<li>Then, I scheduled the CronJob in every second, don&#8217;t tell me that CronJob can&#8217;t be run less than a minute, <a href="http://www.macosxhints.com/article.php?story=20070516060214429" target="_blank">take a look at this post before saying this</a>.And from each call, the output data was stored in the temporary table.</li>
<li>And, finally from the Ajax the a new PHP page was called which was only accessing the data from temporary table with single row.</li>
</ol>
<p>I did the same benchmarking again to the newly made page(which is accessing data only from temporary table) and saw that CPU usages after the this process reduced drastically.</p>
<p>I know I can further reduce the CPU overhead by storing the temporary data in a text file. You guyz know that I&#8217;m lazy so that part is left for another day.</p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=320&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/12/reduce-cpu-overhead-problem-by-mysql.html/feed</wfw:commentRss>
		<slash:comments>40</slash:comments>
		</item>
		<item>
		<title>PHP Framworks !! Why , when and which ?</title>
		<link>http://roshanbh.com.np/2008/11/php-framworks-why-when-and-which.html</link>
		<comments>http://roshanbh.com.np/2008/11/php-framworks-why-when-and-which.html#comments</comments>
		<pubDate>Mon, 17 Nov 2008 10:57:51 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[coding technique]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[php framework]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=311</guid>
		<description><![CDATA[Well!! I know it&#8217;s been a long time, but what to do so many things to do and I&#8217;m having hard time to maintain this blog these days.Hope I will be regular like I was before. Today, I&#8217;m going to talk about some of the popular MVC PHP frameworks. A few people has asked me [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F11%2Fphp-framworks-why-when-and-which.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F11%2Fphp-framworks-why-when-and-which.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Well!! I know it&#8217;s been a long time, but what to do so many things to do and I&#8217;m having hard time to maintain this blog these days.Hope I will be regular like I was before. Today, I&#8217;m going to talk about some of the popular MVC PHP frameworks. A few people has asked me what is CakePHP, or What is CodeIgniter? How to to use them ? When to use them ? Today, I&#8217;m going to talk about PHP frameworks which I&#8217;ve used. Please note that the choice of choosing a framework is personal preference and the statement and this post is not going to say that this framework is better than this framework.<br />
<span id="more-311"></span></p>
<h4>What are the benefits of using MVC PHP frameworks ?</h4>
<p>Well there are many benefits of using PHP frameworks, let&#8217;s see some of the main benefits of using them.</p>
<ol>
<li>They PHP frameworks follows some <a href="http://en.wikipedia.org/wiki/Design_pattern_(computer_science)" target="_blank">design pattern</a>, so when you use these framework you&#8217;ve to follow their coding convention which makes your code clean and extensible for future purpose.</li>
<li>The Popular PHP frameworks like <a href="http://www.cakephp.org" target="_blank">CakePHP</a>, <a href="http://www.codeigniter.com">CodeIgniter</a>, <a href="http://framework.zend.com" target="_blank">Zend Framework</a> , <a href="www.symfony-project.org" target="_blank">Symfony</a> follows <a href="http://en.wikipedia.org/wiki/Model-view-controller">Model View Controller(MVC) design pattern</a> which separates business logic from user interface making the code cleaner and extensible.</li>
<li>As everybody can guess, these frameworks contains   a lot of libraries to make your job easier. For example, to validate a from you don&#8217;t have write much code as you&#8217;ve to in normal coding scenario, just few lines of code calling the library might be enough for it.</li>
<li>While working on a large project in a team, these MVC PHP framework will be a great tool for development as you can assign a developer to develop MVC part of a module for a developer and integration will be quite easy of these developed module at final level.</li>
<li>These MVC framework will really helps you to develop the project rapidly, if you know one framework well then you&#8217;ll never worry about the project deadline.</li>
<li>Most of these MVC frameworks uses clear url approach making your web project SEO friendly.</li>
</ol>
<p>Furthermore, if you want charge money to visitors who download or access  content of your website then this software is highly useful.</p>
<h4>What are disadvantage of using MVC PHP frameworks?</h4>
<p>A coin has two parts similarly a bright stuff always have dark part as well .</p>
<ol>
<li>Different framework have different coding convention, Depending upon the the framework, you&#8217;ll have to learn coding convention for the framework you want to follow. So depending upon the framework, it might to struggle at the beginning.</li>
<li>While coding  using these framework, sometime you&#8217;ll not find any library or helpers which might be useful for you so you&#8217;ll have to struggle bit at that time.</li>
<li>If you don&#8217;t have OOP experience then PHP MVC framework are not you. First build a solid knowledge of OOP with PHP then only think about choosing any framework.</li>
<li>PHP frameworks are not for the small projects from my point of view, because in a very simple project custom coding will work faster than setting up a framework.</li>
</ol>
<h4>Which framework should I choose?</h4>
<p>This is the one of the most discussed question about the PHP framworks.  So it depends upon particular person and project which framework will best suit for you. But depending upon my experience, I can show you some way to choose the framework.</p>
<ol>
<li>If you&#8217;re just want to use MVC framework for your next project, then I suggest you to go for <a href="http://www.codeigniter.com"><strong>CodeIgniter</strong></a>. It is very easy to learn and well-documented.Furthermore, it&#8217;s very flexible because it is not so strict on naming conventions etc. Furthermore, Model is optional while coding in codeIgniter so it is not necessary to use model for each controllers.</li>
<li>If you&#8217;re coding architecture savvy, then I suggest you to go with <a href="http://www.cakephp.org" target="_blank"><strong>CakePHP</strong></a>, probably the most popular PHP framework but I must admit. This framework&#8217;s coding style is similar to Ruby on Rails and naming conventions are strict in this framework.So if you&#8217;re working on a huge project in a team then this project will be the right choice for you.</li>
<li>If you&#8217;ve to use a lot web services external APIs in your project then<strong> <a href="http://framework.zend.com" target="_blank">Zend Framework</a></strong> will be right choice for you, it contains huge libraries for external APIs compared to any other PHP MVC framework. The main benefits of this framework is that you can use them as components(without using MVC) in your project or you can follow Zend framework&#8217;s MVC architecture to develop your project. The other benefits of this framework is that you can use it inside any of the above two MVC frameworks. And, this framework one of the most favourite of people when I conducted the poll for the <strong><a href="roshanbh.com.np/2008/06/which-is-the-best-php-framework.html">best PHP framework</a></strong> ?</li>
</ol>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=311&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/11/php-framworks-why-when-and-which.html/feed</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>Creating and Parsing JSON data with PHP</title>
		<link>http://roshanbh.com.np/2008/10/creating-parsing-json-data-php.html</link>
		<comments>http://roshanbh.com.np/2008/10/creating-parsing-json-data-php.html#comments</comments>
		<pubDate>Sat, 04 Oct 2008 18:10:51 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[how-to]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[json]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=293</guid>
		<description><![CDATA[Yesterday, I was in a party and a guy came near to me and asked me what is JSON and how can handle it via PHP. Today, I&#8217;m going to tell you something about JSON data and how we can handle them via PHP. Although, JSON stands JavaScript Object Notation, it is used by many [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F10%2Fcreating-parsing-json-data-php.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F10%2Fcreating-parsing-json-data-php.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p style="text-align: justify;">Yesterday, I was in a party and a guy came near to me and asked me what is JSON and how can handle it via PHP. Today, I&#8217;m going to tell you something about JSON data and how we can handle them via PHP. Although, JSON stands <strong><a href="http://www.json.org/" target="_blank">JavaScript Object Notation</a></strong>, it is used by many other technologies like PHP and Java for data interchange format over the Internet.</p>
<p><span id="more-293"></span></p>
<h4>What is JSON?</h4>
<p style="text-align: justify;">JSON is ultra-weight data interchange data format used over the internet for transferring the data. While XML is a dominant data interchange format over the internet but JSON is less complex and light-weight data.</p>
<p style="text-align: justify;">Though it was first made to be used with JavaScript for accessing remote data, it is now used by many other languages because JSON data is platform independent data format.</p>
<h4>Data Types and Example of JSON data</h4>
<p>JSON supports various kind of data types which included numbers, strings, booleans as well as array datas and obviously object (collection of key:value pairs, comma-separated and enclosed in curly brackets).</p>
<p>Now, let&#8217;s look at the example of simple format of JSON data for a detail of a employee,</p>
<pre class="prettyprint" style="overflow:auto">{"id":"1","name":"mike","country":"usa","office":["microsoft","oracle"]}</pre>
<h4>Creating and Parsing JSON data format in PHP</h4>
<p>To handle JSON data there is <a href="http://www.php.net/json" target="_blank">JSON extension</a> in PHP which is aviable after PHP 5.2.0. Two funcitons : <a href="http://www.php.net/manual/en/function.json-encode.php">json_encode()</a> and <a href="http://www.php.net/manual/en/function.json-decode.php">json_decode()</a> are very useful converting and parsing JSON data through PHP.</p>
<p>First of all, let&#8217;s look at the PHP code to create the JSON data format of above example using array of PHP.</p>
<pre class="prettyprint" style="overflow:auto">$json_data = array ('id'=&gt;1,'name'=&gt;"mike",'country'=&gt;'usa',"office"=&gt;array("microsoft","oracle"));
echo json_encode($json_data);</pre>
<p>The above code generates the JSON data exactly as above. Now, let&#8217;s decode above JSON data in PHP.</p>
<pre class="prettyprint" style="overflow:auto">$json_string='{"id":1,"name":"mike","country":"usa","office":["microsoft","oracle"]} ';
$obj=json_decode($json_string);</pre>
<p>Now, the $obj variable contains JSON data parsed in PHP object which you can display using code below.</p>
<pre class="prettyprint" style="overflow:auto">echo $obj-&gt;name; //displays mike
echo $obj-&gt;office[0]; //displays microsoft</pre>
<p>As you can guess,$obj-&gt;office is an array and you can loop through it using <a href="http://www.php.net/foreach" target="_blank">foreach</a> loop of PHP,</p>
<pre class="prettyprint" style="overflow:auto">foreach($obj-&gt;office as $val)
    echo $val;</pre>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=293&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/10/creating-parsing-json-data-php.html/feed</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
		<item>
		<title>6 free ajax chat applications using PHP</title>
		<link>http://roshanbh.com.np/2008/09/free-ajax-chat-applications-php.html</link>
		<comments>http://roshanbh.com.np/2008/09/free-ajax-chat-applications-php.html#comments</comments>
		<pubDate>Tue, 23 Sep 2008 12:02:37 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[ajax]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[ajax chat]]></category>
		<category><![CDATA[chat]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=279</guid>
		<description><![CDATA[While talking about chat application, these days people hate those kind application made in PHP which need page refreshing. In this post, I&#8217;ll show you six different free Ajax chat applications which might be very useful if you&#8217;ve to use Ajax based chat application. Depending upon the requirement of your chat application, you can use [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F09%2Ffree-ajax-chat-applications-php.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F09%2Ffree-ajax-chat-applications-php.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>While talking about chat application, these days people hate those kind application made in PHP which need page refreshing. In this post, I&#8217;ll show you six different free Ajax chat applications which might be very useful if you&#8217;ve to use Ajax based chat application. Depending upon the requirement of your chat application, you can use them. I might have missed another good Ajax based chat application, if you find any the please post it to the comments.<br />
<span id="more-279"></span></p>
<h4><a href="https://blueimp.net/ajax/" target="_blank">Ajax Chat from http://blueimp.net</a></h4>
<pre style="overflow:auto"><a href="https://blueimp.net/ajax/" target="_blank"><img title="ajax-chat-blueimp" src="http://roshanbh.com.np/wp-content/uploads/2008/09/ajax-chat-blueimp.png" border="0" alt="Free Ajax chat application using PHP" /></a></pre>
<p>A powerful Ajax chat application with a lot of features at free of cost. Customize the layout and Use it in your project.</p>
<h4><a href="http://ajaxim.com/" target="_blank">Ajax- IM </a></h4>
<pre style="overflow:auto"><a href="http://ajaxim.com/" target="_blank"><img title="ajax-im" src="http://roshanbh.com.np/wp-content/uploads/2008/09/ajax-im.gif" border="0" alt="" /></a></pre>
<p>It is not a only a chat application, it is a instant messenger that&#8217;s why it is named as Ajax-IM. Very useful for implementing in community based websites.</p>
<h4><a href="http://www.phpfreechat.net/" target="_blank">PHPfreeChat </a></h4>
<pre><a href="http://www.phpfreechat.net/" target="_blank"><img class="alignnone size-full wp-image-280" title="ajax-chat-phpfreechat" src="http://roshanbh.com.np/wp-content/uploads/2008/09/ajax-chat-phpfreechat.gif" border="0" alt="" width="400" height="251" />
</a></pre>
<p>Another great Ajax chat application build in PHP.Very easy to customize and use. You can even create rooms for chatting as well.</p>
<h4><a href="http://www.sterryit.com/chatr/" target="_blank">Chatr </a></h4>
<pre><a href="http://www.sterryit.com/chatr/" target="_blank"><img class="alignnone size-full wp-image-282" title="chatr" src="http://roshanbh.com.np/wp-content/uploads/2008/09/chatr.gif" border="0" alt="" width="400" height="227" /></a></pre>
<p>Another simple ajax chat application with limited functionality built in PHP.</p>
<h4><a href="http://www.ajaxchat.org/About/AboutFreeChat.html" target="_blank">Ajax chat from Ajax-chat.org </a></h4>
<pre><a href="http://www.ajaxchat.org/About/AboutFreeChat.html" target="_blank"><img class="alignnone size-full wp-image-283" title="ajax-chat-org" src="http://roshanbh.com.np/wp-content/uploads/2008/09/ajax-chat-org.gif" border="0" alt="" width="400" height="181" /></a></pre>
<p>Very simple, lightweight and easy to use another Ajax chat application built in PHP.</p>
<h4><a href="http://blogoscoped.com/chat/help.php5" target="_blank">Ajax chat from Blogoscopted </a></h4>
<pre><a href="http://blogoscoped.com/chat/help.php5" target="_blank"><img class="alignnone size-full wp-image-284" title="blogoscopted-ajax-chat" src="http://roshanbh.com.np/wp-content/uploads/2008/09/blogoscopted-ajax-chat.jpg" border="0" alt="" width="360" height="261" /></a></pre>
<p>Fancy and avatar based ajax chat application built in PHP. As you can see in the above image, it looks like you&#8217;re really inside a chat room for chtting.</p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=279&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/09/free-ajax-chat-applications-php.html/feed</wfw:commentRss>
		<slash:comments>37</slash:comments>
		</item>
		<item>
		<title>Solving European characters (Western charset) problem with Ajax and PHP</title>
		<link>http://roshanbh.com.np/2008/09/solving-european-characters-western-charset-problem-with-ajax-and-php.html</link>
		<comments>http://roshanbh.com.np/2008/09/solving-european-characters-western-charset-problem-with-ajax-and-php.html#comments</comments>
		<pubDate>Mon, 15 Sep 2008 18:32:20 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[ajax]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[ajax problem]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=276</guid>
		<description><![CDATA[Today, I would like to tell you how to handle character set problem which occurs during the data fetched from PHP using Ajax mainly on the western characters(European charset).Lots of people asked me about this problem where these European charset is displayed in unreadable format after fetching it from ajax. Problem with European Charset with [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F09%2Fsolving-european-characters-western-charset-problem-with-ajax-and-php.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F09%2Fsolving-european-characters-western-charset-problem-with-ajax-and-php.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Today, I would like to tell you how to handle character set problem which occurs during the data fetched from PHP using Ajax mainly on the western characters(European charset).Lots of people asked me about this problem where these European charset is displayed in unreadable format after fetching it from ajax.<br />
<span id="more-276"></span></p>
<h4>Problem with European Charset with Ajax and PHP</h4>
<p>Suppose that I&#8217;ve the following code in PHP file, which output the string which contain the european characters.</p>
<pre class="prettyprint" style="overflow:auto">&lt;?php
  $str="€-accentuée";
  echo $str;
?&gt;</pre>
<p>Now, let&#8217;s use the Ajax from JavaScript using Jquery Code to fetch the data from PHP.</p>
<pre class="prettyprint" style="overflow:auto">&lt;script type="text/javascript"&gt;
$(function()
{
  $('#charsetdiv').load("test2.php");
});
&lt;/script&gt;
&lt;div id="charsetdiv"&gt;&lt;/div&gt;</pre>
<p>If you&#8217;ve not used jQuery then you might be wondering about the ajax code, you can check the <a href="http://roshanbh.com.np/2008/03/jquery-benefits-examples-free-ebook.html">benefits of jquery</a> from this post and download <a href="http://roshanbh.com.np/2008/03/jquery-benefits-examples-free-ebook.html">free ebook of jQuery</a>.</p>
<p>After getting value from Ajax, the division with id &#8220;charsetdiv&#8221;, let&#8217;s look at the output.</p>
<pre class="prettyprint" style="overflow:auto">?-accentu?e</pre>
<h4>Solving western Character Set problem with Ajax and PHP</h4>
<p style="text-align: justify;">The above problem is occurred because of not defining proper charset to these European characters. We can solve this problem by sending the header which define the appropriate Character Set for these characters.Let&#8217;s see, how I solve this problem just adding the header which define the charset Windows-1256 &#8211; which support Arabic as well as European characters.</p>
<pre class="prettyprint" style="overflow:auto">&lt;?php
  header("Content-Type: text/html; charset=Windows-1256\n");
  $str="€-accentuée";
  echo $str;
?&gt;</pre>
<p>After adding that header in PHP, you&#8217;ll get the appropriate european characters in  your Ajax enabled application.</p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=276&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/09/solving-european-characters-western-charset-problem-with-ajax-and-php.html/feed</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Solving Floating point number precision lost problem in PHP</title>
		<link>http://roshanbh.com.np/2008/09/floating-point-number-precision-lost-problem-php.html</link>
		<comments>http://roshanbh.com.np/2008/09/floating-point-number-precision-lost-problem-php.html#comments</comments>
		<pubDate>Mon, 08 Sep 2008 18:07:59 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[tips and technique]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=268</guid>
		<description><![CDATA[The problem of precision lost in floating point number in PHP haunted me for about 10 minutes yesterday but I quickly figured out the problem and solved it as I was aware of this problem. But, I would like to post here it here so that many others PHP programmers, who are not aware with [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F09%2Ffloating-point-number-precision-lost-problem-php.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F09%2Ffloating-point-number-precision-lost-problem-php.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p style="text-align: justify;">The problem of precision lost in floating point number in PHP haunted me for about 10 minutes yesterday but I quickly figured out the problem and solved it as I was aware of this problem. But, I would like to post here it here so that many others PHP programmers, who are not aware with this kind of problem ,get solution easily and don&#8217;t get stuck with it.</p>
<p><span id="more-268"></span></p>
<h4>Calculation problem floating Point number in PHP</h4>
<p style="text-align: justify;">First of all, let me show you a small piece of example of the PHP code which I was working on.</p>
<pre class="prettyprint" style="overflow:auto">$no_of_time=(0.60-0.55)*100;
var_dump($no_of_time); //displays float(5)
for($i=1;$i&lt;=$no_of_time;$i++)
{
   echo $i;
}</pre>
<p style="text-align: justify;">In the above code,  the line <span style="color: #000080;">var_dump($no_of_time);</span> displays float(5). Ok, this is a expected result. But what about the loop, which runs just for 4 time. The above loop runs just for four time although var_dump () outputs that it is 5. Yes, it is 5 but with lost precision and that why never ever trust on the regular arithematic calculation with the floating point numbers in PHP. It always gives the wrong result because of the problem of lost precision. You can also see this warning in the <a href="http://www.php.net/float" target="_blank">PHP&#8217;s website</a>.</p>
<h4>Solving the problem of floating point precision in PHP</h4>
<p style="text-align: justify;">To solve this problem in floating point number, you need the function which calculates and support the calculation of floating point number of any precision. And, I recommend you to use <a href="http://www.php.net/manual/en/ref.bc.php">BC Math functions</a>, the binary calculator, of PHP for calculations  of floating point number to prevent yourself from the problem of precision lost. But note down that, these functions always returns calculated output as string.Now, let&#8217;s try to solve the problem of above code rewrite it using <a href="http://www.php.net/bcsub" target="_blank">bcsub</a> and <a href="http://www.php.net/bcmul" target="_blank">bcmul</a> functions of PHP.</p>
<pre class="prettyprint" style="overflow:auto">$no_of_time=bcmul(bcsub(0.60,0.55,2),100);
var_dump($no_of_time); //display string(1) "5"
for($i=1;$i&lt;=$no_of_time;$i++)
{
   echo $i;
}</pre>
<p style="text-align: justify;">Now the above, loop runs 5 times without any problem.</p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=268&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/09/floating-point-number-precision-lost-problem-php.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Changing textbox value from dropdown list using Ajax and PHP</title>
		<link>http://roshanbh.com.np/2008/09/change-textbox-value-dropdown-list-ajax-php.html</link>
		<comments>http://roshanbh.com.np/2008/09/change-textbox-value-dropdown-list-ajax-php.html#comments</comments>
		<pubDate>Thu, 04 Sep 2008 19:10:00 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[ajax]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=253</guid>
		<description><![CDATA[Yesterday Tarquin macey asked me how can we change the value of the textbox based using Ajax and PHP based on the changing value of the dropdown list.Today, I&#8217;ve come up with a solution from him.In this post, you&#8217;ll see how to get the currency code of a country from PHP using Ajax and this [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F09%2Fchange-textbox-value-dropdown-list-ajax-php.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F09%2Fchange-textbox-value-dropdown-list-ajax-php.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p style="text-align: justify;">Yesterday   <a href="http://www.tarquinm.com/" target="_blank">Tarquin macey</a> asked me how can we change the value of the textbox based using Ajax and PHP based on the changing value of the dropdown list.Today, I&#8217;ve come up with a solution from him.In this post, you&#8217;ll see how to get the currency code of a country from PHP using Ajax and this currency code will replace the value of textbox each time the dropdown list changes.</p>
<p><span id="more-253"></span></p>
<p><strong><a href="http://roshanbh.com.np/examples/dropdown-textbox-ajax" target="_blank">View Live Demo</a> </strong></p>
<h4>Writing Code for changing textbox value from dropdown list using Ajax and PHP</h4>
<p>After looking at the above demo, let&#8217;s start writing code for the changing the currency code value in the textbox form Ajax using PHP when you changes the country from the dropdown list.</p>
<p><strong>HTML Code</strong></p>
<pre class="prettyprint" style="overflow:auto">&lt;select name="country" onChange="getCurrencyCode('find_ccode.php?country='+this.value)"&gt;
 &lt;option value=""&gt;Select Country&lt;/option&gt;
	&lt;option value="1"&gt;USA&lt;/option&gt;
	&lt;option value="2"&gt;UK&lt;/option&gt;
	&lt;option value="3"&gt;Nepal&lt;/option&gt;
&lt;/select&gt;
&lt;input type="text" name="cur_code" id="cur_code" &gt;</pre>
<p>As you can in the above code, there are two main components one dropdown list whose name is country and contains the list country in it.The JavaScript function <span style="color: #000080;"><span class="prettyprint" style="overflow:auto">getCurrencyCode</span>()</span> is called when user change value in the list. Note down the name and id of textbox which will have the currency code fetched from Ajax.</p>
<p><strong>JavaScript Code for changing textbox value without refreshing the page<br />
</strong></p>
<pre class="prettyprint" style="overflow:auto">function getCurrencyCode(strURL)
{
  var req = getXMLHTTP();
  if (req)
  {
	//function to be called when state is changed
	req.onreadystatechange = function()
	{
  	  //when state is completed i.e 4
	  if (req.readyState == 4)
	  {
		// only if http status is "OK"
		if (req.status == 200)
		{
			document.getElementById('cur_code').value=req.responseText;
		}
		else
		{
			alert("There was a problem while using XMLHTTP:\n" + req.statusText);
		}
	  }
        }
	req.open("GET", strURL, true);
	req.send(null);
  }
}</pre>
<p style="text-align: justify;">In the first line of the above code, the XMLHTTPRequest object is created using getXMLHTTP() function. To look at the the structure of this function, take a look at this old post <a href="http://roshanbh.com.np/2007/12/change-dropdown-list-options-values-from-database-with-ajax-and-php.html">change the value of dropdown list using Ajax and PHP</a> . After checking the appropriate value of <span style="color: #000080;">readystate</span>(4 means completed) and <span style="color: #000080;">status</span>(200 means ok) property of XMLHTTPRequest object, the value of textbox is replaced with the returned value from PHP using Ajax . The response ,which is can be accessed via <span class="prettyprint" style="overflow:auto">req.responseText property, is written to textbox via the value property of textbox. </span></p>
<p><strong>PHP code for changing the value of textbox using Ajax and PHP </strong></p>
<pre class="prettyprint" style="overflow:auto">&lt;?php
$country=$_REQUEST['country'];
switch($country)
{
	case "1" :
		echo "USD";
		break;
	case "2" :
		echo "GBP";
		break;
	case "3" :
		echo "NPR";
		break;
}
?&gt;</pre>
<p style="text-align: justify;">As you can see the above PHP code, it is fairly simple which just print the currency code value according to the name of country. The value which is in the echo statement is going to returned from PHP via Ajax.</p>
<p><strong><a href="http://roshanbh.com.np/codes/dropdown-textbox-ajax.zip" target="_blank">Download Full Source Code </a></strong></p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=253&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/09/change-textbox-value-dropdown-list-ajax-php.html/feed</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Force download multiple files in a zip archive using PHP</title>
		<link>http://roshanbh.com.np/2008/09/force-download-mutiple-files-zip-archive-php.html</link>
		<comments>http://roshanbh.com.np/2008/09/force-download-mutiple-files-zip-archive-php.html#comments</comments>
		<pubDate>Tue, 02 Sep 2008 16:44:13 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[how-to]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[zip php]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=247</guid>
		<description><![CDATA[In this post, I&#8217;ll show you how can you download the multiples files in a zip archive using PHP. I&#8217;ve made a function in PHP where you&#8217;ve to pass the parameters the array of files to be zipped, the second parameter is file name as which zip archive file has to be downloaded and finally [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F09%2Fforce-download-mutiple-files-zip-archive-php.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F09%2Fforce-download-mutiple-files-zip-archive-php.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p style="text-align: justify;">In this post, I&#8217;ll show you how can you download the multiples files in a zip archive using PHP. I&#8217;ve made a function in PHP where you&#8217;ve to pass the parameters the array of files to be zipped, the second parameter is file name as which zip archive file has to be downloaded and finally the path of files where files to be zipped are located.(assuming that they are all in same folder)</p>
<p><span id="more-247"></span></p>
<h4>PHP function to download mutiple files in a zip archive</h4>
<pre class="prettyprint" style="overflow:auto">//function to zip and force download the files using PHP
function zipFilesAndDownload($file_names,$archive_file_name,$file_path)
{
  //create the object
  $zip = new ZipArchive();
  //create the file and throw the error if unsuccessful
  if ($zip-&gt;open($archive_file_name, ZIPARCHIVE::CREATE )!==TRUE) {
    exit("cannot open &lt;$archive_file_name&gt;\n");
  }

  //add each files of $file_name array to archive
  foreach($file_names as $files)
  {
    $zip-&gt;addFile($file_path.$files,$files);
  }
  $zip-&gt;close();

  //then send the headers to foce download the zip file
  header("Content-type: application/zip");
  header("Content-Disposition: attachment; filename=$archive_file_name");
  header("Pragma: no-cache");
  header("Expires: 0");
  readfile("$archive_file_name");
  exit;
}</pre>
<p style="text-align: justify;"><a href="http://roshanbh.com.np/examples/force-download-zip-php.phps" target="_blank"><strong>Download Source code</strong></a></p>
<p style="text-align: justify;">In the above PHP function, first of all the object of ZipArchive class. Remember that this library is bundled in PHP after the version of PHP 5.2 only.If you&#8217;re using the PHP version older than that one then you&#8217;ve to get it from PECL extension.</p>
<p style="text-align: justify;">After that, we&#8217;ve tried to create the zip arhive with the open() function using the ZIPARCHIVE::CREATE flag.After successfully creating the archive, each files whose names are passed as array are added to zip file using addFile() function of ZipArchive() class.Then, this zip archive is closed using close() function of same class.</p>
<p style="text-align: justify;">And, finally different headers are passed through PHP to force download the newly created zip file.</p>
<h4>Example of Using Above PHP function</h4>
<pre class="prettyprint" style="overflow:auto">  $file_names=array('test.php','test1.txt');
  $archive_file_name='zipped.zip';
  $file_path=dirname(__FILE__).'/';
  zipFilesAndDownload($file_names,$archive_file_name,$file_path);</pre>
<p>The above PHP function call is straighforward and after calling that function you&#8217;ll get the zip archive containing mutiple files passed as array in the first parameter of the function.</p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=247&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/09/force-download-mutiple-files-zip-archive-php.html/feed</wfw:commentRss>
		<slash:comments>48</slash:comments>
		</item>
		<item>
		<title>Get free ebooks of essential PHP and JavaScript tips , tricks &amp; Hacks</title>
		<link>http://roshanbh.com.np/2008/08/free-ebook-essential-php-javascript-tips-tricks-hacks.html</link>
		<comments>http://roshanbh.com.np/2008/08/free-ebook-essential-php-javascript-tips-tricks-hacks.html#comments</comments>
		<pubDate>Sun, 31 Aug 2008 18:45:24 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[ebook]]></category>
		<category><![CDATA[free]]></category>
		<category><![CDATA[free ebook]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=243</guid>
		<description><![CDATA[As you might know that this blog and tradepub.com are providing free magazines to the reader of this blog. You can check the free magazines and E-book in the free magazines resource of this blog. You can find a collection of great resources of IT knowledge from here. And, today I&#8217;m here to highlight the [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F08%2Ffree-ebook-essential-php-javascript-tips-tricks-hacks.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F08%2Ffree-ebook-essential-php-javascript-tips-tricks-hacks.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p style="text-align: justify;">As you might know that this blog and tradepub.com are providing free magazines to the reader of this blog. You can check the free magazines and E-book in the <a href="http://roshanbh.tradepub.com">free magazines</a> resource of this blog. You can find a collection of great resources of IT knowledge from here. And, today I&#8217;m here to highlight the great E-books from sitepoint.com on essential PHP and JavaScript tips , tricks  and other resources.</p>
<p><span id="more-243"></span></p>
<h4>Free E-book on the essential tips, tricks and hacks of JavaScript and PHP</h4>
<p style="text-align: justify;">You can find the great list of resources for the web developer in the list below. You can check them out grab a copy of your E-book right now.</p>
<ul>
<li><strong><a href="http://roshanbh.tradepub.com/free/w_sitb02/" target="_blank">The PHP Anthology: 101 Essential Tips, Tricks &amp; Hacks, 2nd Edition &#8211; Free 207 Page Preview!</a></strong></li>
<li><strong> <a href="http://roshanbh.tradepub.com/free/w_sitb04/" target="_blank">The JavaScript Anthology: 101 Essential Tips, Tricks &amp; Hacks &#8211; Free 158 Page Preview</a></strong></li>
</ul>
<p style="text-align: justify;">Other resources which are be very useful for the web developer. Do check them out and get a copy of yours.</p>
<ul>
<li><strong><a href="http://roshanbh.tradepub.com/free/w_sitb01/" target="_blank">The Principles Of Project Management &#8211; Free 66 Page Preview!</a></strong></li>
<li><strong><a href="http://roshanbh.tradepub.com/free/w_sitb03/" target="_blank">The ASP.NET 2.0 Anthology: 101 Essential Tips, Tricks &amp; Hacks &#8211; Free 156 Page Preview</a></strong></li>
<li><strong><a href="http://roshanbh.tradepub.com/free/w_sitb05/" target="_blank">Run Your Own Web Server Using Linux &amp; Apache &#8211; Free 191 Page Preview</a></strong></li>
<li><strong><a href="http://roshanbh.tradepub.com/free/w_sitb03/" target="_blank">Remote Replication Best Practices for Oracle 10g using XP Continuous Access</a></strong></li>
<li><strong><a href="http://roshanbh.tradepub.com/free/w_hp24" target="_blank">Best Practices for Implementing HP Quality Center Software</a></strong></li>
</ul>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=243&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/08/free-ebook-essential-php-javascript-tips-tricks-hacks.html/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Handling array of HTML Form Elements in JavaScript and PHP</title>
		<link>http://roshanbh.com.np/2008/08/handling-array-html-form-elements-javascript-php.html</link>
		<comments>http://roshanbh.com.np/2008/08/handling-array-html-form-elements-javascript-php.html#comments</comments>
		<pubDate>Wed, 27 Aug 2008 19:46:30 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[how-to]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=240</guid>
		<description><![CDATA[Today, I would like to share the way of handling array of HTML FORM elements using JavaScript and PHP.Well, it&#8217;s very easy to get the data from the array of HTML form elements in PHP and using them but in JavaScript it&#8217;s a bit tricky to handle the array of HTML form elements. I had [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F08%2Fhandling-array-html-form-elements-javascript-php.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F08%2Fhandling-array-html-form-elements-javascript-php.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p style="text-align: justify;">Today, I would like to share the way of handling array of HTML FORM elements using JavaScript and PHP.Well, it&#8217;s very easy to get the data from the array of HTML form elements in PHP and using them but in JavaScript it&#8217;s a bit tricky to handle the array of HTML form elements. I had a hard time to handle them via JavaScript in past thats why I&#8217;m posting it here so that people will not have hard time to cope with array of form elements in JavaScript and PHP.</p>
<p><span id="more-240"></span></p>
<h4>Array of HTML form elements</h4>
<p style="text-align: justify;">You can create the array of Form Elements for grouping the similar kind of object or data. The array of elements are very useful in the context where you don&#8217;t know how many similar kind of data user have to enter. For example, you have a form where user have to enter his education qualification then you might not know how many of the textboxes are required for a person and in such kind situation you can dynamically generate array of the elements in the form for entering such kind of information.</p>
<pre class="prettyprint" style="overflow:auto">&lt;input name="education[]" type="text" size="20" maxlength="40" /&gt;
&lt;input name="education[]" type="text" size="20" maxlength="40" /&gt;
&lt;input name="education[]" type="text" size="20" maxlength="40" /&gt;</pre>
<p>As you can in the above code, there are array element of textbox defined with the name &#8220;education&#8221;.Now, let&#8217;s see how can we handle them via JavaScript and PHP.</p>
<h4>How to handle array of HTML form elements using PHP</h4>
<p style="text-align: justify;">If you submit the the the form with the above the array of elements then you can assess it via array of $_POST['education'] in PHP. You can use foreach() loop to access the value of the value of these form elements via PHP.</p>
<pre class="prettyprint" style="overflow:auto">foreach($_POST['education'] as $key=&gt;$value)
 echo $key.' '.$value;</pre>
<p style="text-align: justify;">Normally, posted variable are contained within the POST array but when you post the array of Form Elements then at that time the values are contained within the array of array i.e within $_POST['education'] in above exmaple.</p>
<h4>How to handle array of Form elements using JavaScript</h4>
<p style="text-align: justify;">Handling the array of Form element part is a bit tricky. Now, let try to access the values of the above elements using JavaScript. First, let&#8217;s store the above object in a JavaScript variable</p>
<pre class="prettyprint" style="overflow:auto">var mutli_education = document.form_name.elements["education[]"];</pre>
<p style="text-align: justify;">After storing the object in the variable, we can access the individual variables in the following way in JavaScript</p>
<pre class="prettyprint">for(i=0;i&lt;mutli_education.length;i++)
{
 alert(mutli_education[i].value);
}</pre>
<p style="text-align: justify;">As you can see, you can get how many elements are there in the array using the <span style="color: #000080;">lengh </span>property and you can use the <span style="color: #000080;">value</span> property to get the value of the indivisual element.</p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=240&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/08/handling-array-html-form-elements-javascript-php.html/feed</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>How to filter user submitted data easily in PHP?</title>
		<link>http://roshanbh.com.np/2008/08/how-to-filter-user-submitted-data-easily-in-php.html</link>
		<comments>http://roshanbh.com.np/2008/08/how-to-filter-user-submitted-data-easily-in-php.html#comments</comments>
		<pubDate>Tue, 12 Aug 2008 18:45:27 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[web security. tips]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=217</guid>
		<description><![CDATA[Yesterday, I saw one of my friend was working on the the contact form and was filtering the user input data(posted variables) individually. He was using a function in PHP to filter the input and using  tedious approach while calling the filtering function for each variables with coding  each of them in single line . [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F08%2Fhow-to-filter-user-submitted-data-easily-in-php.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F08%2Fhow-to-filter-user-submitted-data-easily-in-php.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p align="justify">Yesterday, I saw one of my friend was working on the the contact form and was filtering the user input data(posted variables) individually. He was using a function in PHP to filter the input and using  tedious approach while calling the filtering function for each variables with coding  each of them in single line . Today, I&#8217;m going to show you how can you filter the posted variables easily using callback function in PHP.</p>
<p><span id="more-217"></span></p>
<h4>PHP function to filter the user supplied data.</h4>
<pre class="prettyprint">function filter_data($val)
{
  return htmlentities($val,ENT_QUOTES);
}</pre>
<p align="justify">This is just a example of very simple function is PHP to filter the user ssubmitted data.But ,you can add more code according to your requirement to make this function robust.</p>
<h4>Common programmer&#8217;s approach to filter submitted data in PHP</h4>
<pre class="prettyprint">$name=filter_data($_POST['name']);
$email=filter_data($_POST['email']);
$website=filter_data($_POST['website']);</pre>
<p align="justify">It was the approach which I&#8217;ve used in beginning of my career and most of the beginner PHP programmer use this approach to filter the posted variables.And, the above list can be long if there are more posted data.At that time, it will be very irritating to use the same kind of line in many places.</p>
<h4>Using array_map() function to filter the posted data in PHP</h4>
<p>As you know, POST variables are <a href="http://www.php.net/manual/en/reserved.variables.post.php" target="_blank">super global array</a> in PHP and you can use <a href="http://www.php.net/array_map" target="_blank">array_map()</a> function in PHP to filter the input using the callback function. Let&#8217;s see how you can filter the the posted data easily,</p>
<pre class="prettyprint">$post=array_map("filter_data",$_POST);</pre>
<p align="justify">As you can, each values of POST variables is mapped into another array using a call back function filter_data() which is defined above.</p>
<p>Now, you can access the filtered variables easilly with <span class="prettyprint"><strong>$post['name']</strong></span> or <strong>$post['email']</strong> etc.</p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=217&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/08/how-to-filter-user-submitted-data-easily-in-php.html/feed</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>Web Services and PHP &#8211; SOAP vs XML-RPC vs REST</title>
		<link>http://roshanbh.com.np/2008/07/web-services-php-soap-vs-xml-rpc-vs-rest.html</link>
		<comments>http://roshanbh.com.np/2008/07/web-services-php-soap-vs-xml-rpc-vs-rest.html#comments</comments>
		<pubDate>Thu, 31 Jul 2008 12:23:35 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[SOAP]]></category>
		<category><![CDATA[XML-RPC]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=183</guid>
		<description><![CDATA[What is web services? In a typical web surfing scenario, a visitor visits a website and use the functionality provided by that particular website.HTTP request is send to server from web browsers and server responses are translated by browser to display the desired result of the visitor. But, this scenario has been changed in the [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F07%2Fweb-services-php-soap-vs-xml-rpc-vs-rest.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F07%2Fweb-services-php-soap-vs-xml-rpc-vs-rest.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<h4>What is web services?</h4>
<p style="text-align: justify;">In a typical web surfing scenario, a visitor visits a website and use the functionality provided by that particular website.HTTP request is send to server from web browsers and server responses are translated by browser to display the desired result of the visitor. But, this scenario has been changed in the recent days. You don&#8217;t need to visit the particular website to use their service and functionality if they are providing web services. <strong>Web services</strong> are set of platform independent exposed APIs(functions) which can be used used from remote server over the Internet. There are basically two parties involved in this, one which provides a set of exposed APIs and the another one ,commonly know as web services consumers,is the party which uses the functionality and services provided by web services providing party.</p>
<p><span id="more-183"></span></p>
<p style="text-align: justify;">There are different method for providing web services but the most common are<a href="http://en.wikipedia.org/wiki/SOAP" target="_blank"> SOAP</a>, <a href="http://en.wikipedia.org/wiki/Xml-rpc" target="_blank">XML-RPC</a> and <a href="http://en.wikipedia.org/wiki/REST">REST</a> .</p>
<h4>SOAP</h4>
<p style="text-align: justify;"><a href="http://en.wikipedia.org/wiki/SOAP" target="_blank">SOAP</a> was the acronym of <strong>Simple Object Access Protocal</strong> but this acronym was dropped in the version of 1.2 of SOAP. It is method for exchanging XML based message over the Internet for providing and consuming web services. SOAP message are transferred forming the SOAP-Envelope.You can view the typical <a href="http://www.w3schools.com/soap/soap_syntax.asp" target="_blank">SOAP Message articture from here</a>. SOAP is widely criticized for it&#8217;s design complexity.</p>
<p style="text-align: justify;">In PHP 5, there is built-in extension for the providing and consuming web services. But, I personally prefer <a href="http://sourceforge.net/projects/nusoap/" target="_blank">Nusoap</a> toolkit of PHP for providing and consuming web services using SOAP in PHP.</p>
<h4>XML-RPC</h4>
<p><a href="http://en.wikipedia.org/wiki/Xml-rpc" target="_blank">XML-RPC (remote procedure call)</a> another way of providing and consuming web services. It uses XML to encode and decode the remote procedure call along with it&#8217;s parameter. Compared to the articture of SOAP, it has simpler architecture. You can even define data type of parameters of procedure in XML-RPC. You can visit the official website <a href="www.xmlrpc.com">www.xmlrpc.com </a> to know more about XML-RPC.</p>
<p style="text-align: justify;">In PHP, there is extension <a href="http://www.php.net/xmlrpc" target="_blank">which contain various functions</a> for facilating XML-RPC request and response. But the functions <a href="http://www.php.net/xmlrpc_encode_request" target="_blank">xmlrpc_encode_request()</a> and <a href="http://www.php.net/xmlrpc_decode_request">xmlrpc_decode_request()</a> available in PHP is very useful for when it comes to encode and decode XML-RPC request and response.</p>
<p style="text-align: justify;">I&#8217;ve built  <a href="http://roshanbh.com.np/tools/nepali-currency-converter/" target="_blank">Nepali Currency Converter</a> using XML-RPC web services provided by <a href="http://foxrate.org">foxrate.org</a>.</p>
<h4>REST</h4>
<p style="text-align: justify;">Representational State Trasfer(REST)  is comparatively simpler method for providing and consuming web services. Nowadays, this method is becoming popular in the arena of web services. Unlike above two method, it is not necessary to use XML as a data interchange format in REST. REST architecture is basically focused on two things : <strong>Resources</strong> and <strong>Interface</strong>.RESTful  is another term to define REST web services .</p>
<p style="text-align: justify;"><strong>Resources</strong> are application&#8217;s state and functionality which is represented by a unique URL.  The resources share a uniform <strong>interface</strong> to transfer the state between the client and server.</p>
<p style="text-align: justify;">For example the URL, http://example.com/product/11 can be a <strong>resource</strong>.Suppose, GET method is used to retrieve product detail from that URL, POST method is used to modify the production information and DELETE method can be used to delete the product from the same URL. Here, the HTTP methods works as a <strong>interface</strong> to access the resources.</p>
<p style="text-align: justify;">Talking about  PHP, the format of information(representation) returned can be in XML, JSON or even in HTML format. <a href="http://www.php.net/dom" target="_blank">DOM functions</a>, <a href="http://www.php.net/simplexml">SimpleXML functions</a> and <a href="http://www.php.net/json" target="_blank">JSON functions</a> comes handy when you are handling RESTful interfaces in PHP.</p>
<p style="text-align: justify;">I also want to know your view. Please participate in the poll below.</p>
<p style="text-align: justify;">[poll id="3"]</p>
<p style="text-align: justify;">
<p style="text-align: justify;">
<p style="text-align: justify;">
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=183&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/07/web-services-php-soap-vs-xml-rpc-vs-rest.html/feed</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Getting country , city name from IP address in PHP</title>
		<link>http://roshanbh.com.np/2008/07/getting-country-city-name-from-ip-address-in-php.html</link>
		<comments>http://roshanbh.com.np/2008/07/getting-country-city-name-from-ip-address-in-php.html#comments</comments>
		<pubDate>Thu, 17 Jul 2008 10:41:18 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[how-to]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[api]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=164</guid>
		<description><![CDATA[Yesterday, miaki asked me how can we get the country name from the IP address in PHP. Today, I&#8217;ve come up with the answer of this question. I&#8217;ve used the API from hostip.info to fetch the country name , city name and country code from the given IP address. I&#8217;ve mad this function in PHP [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F07%2Fgetting-country-city-name-from-ip-address-in-php.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F07%2Fgetting-country-city-name-from-ip-address-in-php.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p style="text-align: justify;">Yesterday,  <a rel="nofollow" href="http://rowebsoft.com">miaki</a> asked me how can we get the country name from the IP address in PHP. Today, I&#8217;ve come up with the answer of this question. I&#8217;ve used the API from <a href="http://www.hostip.info/use.html">hostip.info</a> to fetch the country name , city name and country code from the given IP address. I&#8217;ve mad this function in PHP which uses XML response from  hostip.info and extracted country name, city name and country code using regular expression.</p>
<p><span id="more-164"></span></p>
<h4>Function to return country, city name from IP address in PHP</h4>
<pre class="prettyprint" style="overflow:auto;">function countryCityFromIP($ipAddr)
{
//function to find country and city from IP address
//Developed by Roshan Bhattarai http://roshanbh.com.np

//verify the IP address for the
ip2long($ipAddr)== -1 || ip2long($ipAddr) === false ? trigger_error("Invalid IP", E_USER_ERROR) : "";
$ipDetail=array(); //initialize a blank array

//get the XML result from hostip.info
$xml = file_get_contents("http://api.hostip.info/?ip=".$ipAddr);

//get the city name inside the node &lt;gml:name&gt; and &lt;/gml:name&gt;
preg_match("@&lt;Hostip&gt;(\s)*&lt;gml:name&gt;(.*?)&lt;/gml:name&gt;@si",$xml,$match);

//assing the city name to the array
$ipDetail['city']=$match[2]; 

//get the country name inside the node &lt;countryName&gt; and &lt;/countryName&gt;
preg_match("@&lt;countryName&gt;(.*?)&lt;/countryName&gt;@si",$xml,$matches);

//assign the country name to the $ipDetail array
$ipDetail['country']=$matches[1];

//get the country name inside the node &lt;countryName&gt; and &lt;/countryName&gt;
preg_match("@&lt;countryAbbrev&gt;(.*?)&lt;/countryAbbrev&gt;@si",$xml,$cc_match);
$ipDetail['country_code']=$cc_match[1]; //assing the country code to array

//return the array containing city, country and country code
return $ipDetail;

}</pre>
<p style="text-align: justify; font-weight: bold;"><a href="http://roshanbh.com.np/codes/country-ip.phps">Download Source Code</a></p>
<p style="text-align: justify;">As you can see, I&#8217;ve documented all the PHP code and I don&#8217;t think I need explain anymore about that code. Just notice that, this function returns the array containg three key elements &#8220;country&#8221; , &#8220;city&#8221; and &#8220;country_code&#8221;. Each elements have the value of city, country and country code.</p>
<p style="text-align: justify;">Now, look the the how we can use the above function in PHP,</p>
<pre class="prettyprint" style="overflow:auto;">$IPDetail=countryCityFromIP('12.215.42.19');
echo $IPDetail['country']; //country of that IP address
echo $IPDetail['city']; //outputs the IP detail of the city</pre>
<p style="text-align: justify;">Notice that the above PHP function returns the array containing the country , city and country code from IP Address and we can use them in PHP. If you want to know how to get IP address in PHP, you can check this post how you can get <a href="http://roshanbh.com.np/2007/12/getting-real-ip-address-in-php.html">real IP address in PHP</a>.</p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=164&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/07/getting-country-city-name-from-ip-address-in-php.html/feed</wfw:commentRss>
		<slash:comments>48</slash:comments>
		</item>
		<item>
		<title>Getting technorati ranking in PHP without using their API</title>
		<link>http://roshanbh.com.np/2008/07/getting-technorati-ranking-php-without-using-api.html</link>
		<comments>http://roshanbh.com.np/2008/07/getting-technorati-ranking-php-without-using-api.html#comments</comments>
		<pubDate>Tue, 15 Jul 2008 17:07:51 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[how-to]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[technorati]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=163</guid>
		<description><![CDATA[Today, I was going through the Technorati API to find the rank of the blog using PHP. Those who doesn&#8217;t know about Technorati, Technorati is known as the authority for tracking, indexing and ranking the blog sytems. When I went through the Technorati Api, I found that it is not that hard to get the [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float:right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F07%2Fgetting-technorati-ranking-php-without-using-api.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F07%2Fgetting-technorati-ranking-php-without-using-api.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p style="text-align: justify;">Today, I was going through the T<a href="http://www.technorati.com">echnorati</a> API to find the rank of the blog using PHP. Those who doesn&#8217;t know about Technorati, Technorati is known as the authority for tracking, indexing and ranking the blog sytems. When I went through the Technorati Api, I found that it is not that hard to get the ranking of a blog which is indexed in Technorati.You need to get the developer API  key from Technorati and use their Web Services to get the ranking of a blog.</p>
<p><span id="more-163"></span></p>
<p style="text-align: justify;">But, those who are not registered to the Technorati, here is the shortcut method to get the ranking of blogs indexed under Technorati without using their Api. I&#8217;ve used the following  URL of technorati</p>
<p style="text-align: justify;">&#8220;http://www.technorati.com/blogs/&lt;blog-url&gt;&#8221;</p>
<p style="text-align: justify;">and used some regular expression to find the ranking of the blog indexed under technorati withoug using their API.</p>
<h4>PHP code to find the technorati ranking without using API</h4>
<pre class="prettyprint" style="overflow:auto">&lt;?php
//enter the blog url don't include http
$blog_url="roshanbh.com.np";
//seeting the URL for technorati
$technorati_url="http://www.technorati.com/blogs/".$blog_url;
//get the html code of the URL
$html_values=file_get_contents($technorati_url);
//get the string within &lt;div class="rank"&gt;&lt;/div&gt;
preg_match("@&lt;div\b[^&gt;]* class=\"rank\"&gt;(.*?)&lt;/div&gt;@si",$html_values,$matches);
//strip out of the HTML element from the matches
$rankvalue=strip_tags($matches[1]);
//geting the the rank values out of the string
preg_match("/(\d+(,\d+)?(,\d+)?)/",$rank_value,$matches);
//Display the rank.
echo "Technorati rank is : ".$matches[0];
?&gt;</pre>
<p style="text-align: justify;"><strong><a href="http://roshanbh.com.np/codes/technorati.phps" target="_blank">Download Source Code</a></strong></p>
<p style="text-align: justify;">As you can above, I&#8217;ve used <a href="http://www.php.net/file_get_contents" target="_blank">file_get_contens()</a> function of PHP to get the content from Technorati. The rank of the blog if found under the division &#8220;&lt;div class=&#8221;rank&#8221;&gt;&lt;/div&gt;&#8221; in that page of Technorati, you can verify it by viewing the source of that page. After that, I&#8217;ve used few regular expression to find the ranking of the blog in PHP.</p>
<p style="text-align: justify;">One thing you must notice that this code will works under this design of Technorati, if the technorati will change the design then there is no guarantee that this code will work at that scenario.</p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=163&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/07/getting-technorati-ranking-php-without-using-api.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 2/55 queries in 5.179 seconds using disk: basic
Object Caching 2205/2333 objects using disk: basic

Served from: roshanbh.com.np @ 2012-02-08 19:23:43 -->
