<?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; tips and technique</title>
	<atom:link href="http://roshanbh.com.np/category/tips-and-technique/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>Model File upload overlay box using jQuery and Thickbox</title>
		<link>http://roshanbh.com.np/2008/10/model-file-upload-overlay-box-jquery.html</link>
		<comments>http://roshanbh.com.np/2008/10/model-file-upload-overlay-box-jquery.html#comments</comments>
		<pubDate>Sat, 25 Oct 2008 18:17:02 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[how-to]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[file upload]]></category>
		<category><![CDATA[modal]]></category>
		<category><![CDATA[overlay]]></category>
		<category><![CDATA[thickbox]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=303</guid>
		<description><![CDATA[Few times back, sNare asked me how do display wordpress like overlay box where you can pass the variables when you click on the link and manipulate simultaneous actions in the overlay until user choose to close it. Today, I&#8217;ve come up with the solution of this with model upload overlay box using thickbox, a [...]]]></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%2Fmodel-file-upload-overlay-box-jquery.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F10%2Fmodel-file-upload-overlay-box-jquery.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;">Few times back, sNare asked me how do display wordpress like overlay box where you can pass the variables when you click on the link and manipulate simultaneous actions in the overlay until user choose to close it. Today, I&#8217;ve come up with the solution of this with model upload overlay box using <a href="http://jquery.com/demo/thickbox/">thickbox</a>, a jquery plugin. I&#8217;ve used the Iframe content of thickbox while displaying the box as modal box.</p>
<p><span id="more-303"></span><br />
<strong><a href="http://roshanbh.com.np/examples/file-upload-overlay-jquery" target="_blank">LIVE DEMO </a></strong></p>
<h4>How to use the thickbox as modal overlay box?</h4>
<p>Let&#8217;s look at the step by step to use thickbox for passing variables.</p>
<p>First of all, we have to include jQuery JavaScript Library to our page,</p>
<pre class="prettyprint" style="overflow:auto">&lt;script type="text/javascript" src="jquery.js"&gt;&lt;/script&gt;</pre>
<p>After this, include the <a href="http://jquery.com/demo/thickbox/">thickbox</a> plugin of jQuery,</p>
<pre class="prettyprint" style="overflow:auto">&lt;script type="text/javascript" src="thickbox-compressed.js"&gt;&lt;/script&gt;</pre>
<p>There is a CSS for using thickbox which also need to linked to the current page,</p>
<pre class="prettyprint" style="overflow:auto">&lt;link rel="stylesheet" href="thickbox.css" type="text/css" media="screen" /&gt;</pre>
<p>Now, let&#8217;s look at the anchor tag which passes the variables to overlay box and keep the overlay at top no matter how many simultaneous accesses occur in the box.</p>
<pre class="prettyprint" style="overflow:auto">&lt;a href="file_upload.php?post_id=5&amp;TB_iframe=true&amp;height=200&amp;width=300&amp;modal=true" class="thickbox" &gt;&lt;strong&gt;Upload Files&lt;/strong&gt;&lt;/a&gt;</pre>
<p>If you want to know how to use the thickbox, then you can checkout their home page which contains good documentation. The main point is, <span style="color: #000080;">class=&#8217;thickbox&#8217; </span>must be used for the displaying the content in overlay.</p>
<h4>How to pass variables to overlay box (thickbox)?</h4>
<p>If you look at the href attribute of anchor tag, you can see clearly that I&#8217;ve passed <span style="color: #003366;">post_id</span> variable with value <span style="color: #003366;">5</span> to <span style="color: #000080;">file_upload.php</span>, which can be easily fetched from PHP using <span style="color: #000080;">$_GET['post_id']</span>.</p>
<h4>How to make overlay box stay opened on simultaneous access?</h4>
<p>Now this is part which many people has asked me how to do it. To use thickbox in this fashion, you&#8217;ve to use it in iframe content mode.The following property of thickbox make it remained open on simultaneous access,</p>
<pre class="prettyprint" style="overflow:auto">TB_iframe=true</pre>
<p>Furthermore, We&#8217;ve used the following property to display the overlay box as modal box.</p>
<pre class="prettyprint" style="overflow:auto">modal=true</pre>
<p><strong><a href="http://roshanbh.com.np/codes/file-upload-overlay-jquery.zip">DOWNLOAD SOURCE CODE </a></strong></p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=303&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/10/model-file-upload-overlay-box-jquery.html/feed</wfw:commentRss>
		<slash:comments>16</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>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>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>Move an object on mouse wheel scroll event using JavaScript</title>
		<link>http://roshanbh.com.np/2008/08/move-object-mouse-wheel-scroll-event-javascript.html</link>
		<comments>http://roshanbh.com.np/2008/08/move-object-mouse-wheel-scroll-event-javascript.html#comments</comments>
		<pubDate>Tue, 19 Aug 2008 08:27:34 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[how-to]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[mouse]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=226</guid>
		<description><![CDATA[Today, I&#8217;ve come along with another post where you&#8217;ll see how to move a object within web page when you scroll the mouse wheel using JavaScript.In this example, when you move the mouse wheel the object i.e div moves upwards or downwards depending upon the scrolling direction the mouse wheel. Now, let&#8217;s look at 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%2Fmove-object-mouse-wheel-scroll-event-javascript.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F08%2Fmove-object-mouse-wheel-scroll-event-javascript.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&#8217;ve come along with another post where you&#8217;ll see how to move a object within web page when you scroll the mouse wheel using JavaScript.In this example, when you move the mouse wheel the object i.e <strong>div </strong>moves upwards or downwards depending upon the scrolling direction the mouse wheel. Now, let&#8217;s look at the detail of this tutorial in JavaScript.</p>
<p><span id="more-226"></span></p>
<h4><a href="http://roshanbh.com.np/examples/mouse-wheel.html" target="_blank">View Live Demo</a></h4>
<h4>HTML and CSS for object to be scrolled on mouse wheel movement</h4>
<pre class="prettyprint" style="overflow:auto ">&lt;div id="object"&gt;This block moves as you move mouse wheel.&lt;/div&gt;</pre>
<p style="text-align: justify;">As you can see above code, the object which is going to be moved is placed in the division with id <strong>object</strong>. For the above division, I&#8217;ve defined style and you can see the CSS code below. Remember that ,you can change the below CSS code according to your need but remember that the position should be <strong>absolute</strong>.</p>
<pre style="border: 1px solid #888888; padding: 2px"><span style="color: #ff00ff;">#object {</span>
<span style="color: #333399;">font-weight:bold;
background:yellow;
padding:5px;
width:300px;
position:absolute;
left:500px;
top:200px;</span>
<span style="color: #ff00ff;">}</span></pre>
<h4>JavaScript code for handling mouse scroll event.</h4>
<pre class="prettyprint" style="overflow:auto ">window.onload = function()
{
  //adding the event listerner for Mozilla
  if(window.addEventListener) document.addEventListener('DOMMouseScroll', moveObject, false);
  //for IE/OPERA etc
  document.onmousewheel = moveObject;
}</pre>
<p>First of all, we need to attach the mouse wheen scroll event to the document.As you can see in the first line of above function,  event listner &#8220;moveObject&#8221; is added to the mouse scroll event in the document for Mozilla browsers and in the second line event handler &#8220;moveObject&#8221; is called for <strong>document.onmousewheel</strong> event for browsers like IE and Opera etc.</p>
<p>Now look at the mouse wheel scroll event handler function &#8220;moveObject&#8221;</p>
<pre class="prettyprint" style="overflow:auto ">function moveObject(event)
{
  var delta = 0;
  if (!event) event = window.event;
  // normalize the delta
  if (event.wheelDelta)
  {
    // IE &amp; Opera
   delta = event.wheelDelta / 120;
  }
  else if (event.detail) // W3C
  {
    delta = -event.detail / 3;
  }
  var currPos=document.getElementById('object').offsetTop;
  //calculating the next position of the object
  currPos=parseInt(currPos)+(delta*10);
  //moving the position of the object
  document.getElementById('object').style.top=currPos+"px";
}</pre>
<p style="text-align: justify;">As you can see in the above function first the scrolling <strong>delta</strong> value is calculated. The delta variable holds the value  -1 or 1 depending upon the movement of the wheel.</p>
<p style="text-align: justify;">After calculating the detail value, the top offset of the object is taken using <strong>offsetTop</strong> property using JavaScript. After that, the next position of the object is calculated, which is 10 pixel up or down from the current position of the object.</p>
<p style="text-align: justify;">Finally, style.top property is used to set the current position of the object using JavaScript.</p>
<h4><a href="http://roshanbh.com.np/codes/mouse-wheel.zip" target="_blank">Download Full Source Code </a></h4>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=226&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/08/move-object-mouse-wheel-scroll-event-javascript.html/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Making dashed or dotted link using CSS</title>
		<link>http://roshanbh.com.np/2008/08/dashed-dotted-link-css.html</link>
		<comments>http://roshanbh.com.np/2008/08/dashed-dotted-link-css.html#comments</comments>
		<pubDate>Fri, 15 Aug 2008 10:12:28 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[css]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=220</guid>
		<description><![CDATA[Today, one of the friend of my office asked me how to make dotted or dashsed link as he was looking for &#8220;text-decoration&#8221; for making it.Today, I&#8217;ve come up with a very simple technique to make a dotted or dashed hyperlink using CSS.This technique might be known to most of you guys but it might [...]]]></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%2Fdashed-dotted-link-css.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F08%2Fdashed-dotted-link-css.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, one of the friend of my office asked me how to make dotted or dashsed  link as he was looking for &#8220;text-decoration&#8221; for making it.Today, I&#8217;ve come up with a very simple technique to make a dotted or dashed hyperlink using CSS.This technique might be known to most of you guys but it might be useful for those guys who don&#8217;t know about this technique.</p>
<p><span id="more-220"></span></p>
<h4>Making dotted and dashed link using CSS</h4>
<pre style="border: 1px solid #888888; padding: 2px"><span style="color: #ff00ff;">a
{</span>
<span style="color: #333399;">border-bottom:1px dotted #FF0000;
text-decoration:none;
color:#FF0000;</span>
<span style="color: #ff00ff;">}</span></pre>
<p>As, you can can you can use the border-bottom property to add the border in the bottom and then you must specify that text-decoration property to &#8220;none&#8221; to remove the underline from hyperlink which comes default in hyperlink. In the similar fashion, you can create dashed underline link with the following example code.</p>
<pre style="border: 1px solid #888888; padding: 2px"><span style="color: #ff00ff;">a
{</span>
<span style="color: #333399;">border-bottom:1px dashed #FF0000;
text-decoration:none;
color:#FF0000;</span>
<span style="color: #ff00ff;">}</span></pre>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=220&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/08/dashed-dotted-link-css.html/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Making Money from blog with the help of WP Affiliate Elite</title>
		<link>http://roshanbh.com.np/2008/08/making-money-from-blog.html</link>
		<comments>http://roshanbh.com.np/2008/08/making-money-from-blog.html#comments</comments>
		<pubDate>Wed, 13 Aug 2008 11:38:03 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[Others]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[make money]]></category>
		<category><![CDATA[money]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=219</guid>
		<description><![CDATA[Everybody tells me that my blog is under monetized. Ya it is a bitter truth of this blog. I&#8217;m always looking for the better option to make money from this blog. And, you must know that affiliate marketing is one the best and largest method of monetizing your blog. Today, I&#8217;ve purchased a great plugin [...]]]></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%2Fmaking-money-from-blog.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F08%2Fmaking-money-from-blog.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p align="justify">Everybody tells me that my blog is under monetized. Ya it is a bitter truth of this blog. I&#8217;m always looking for the better option to make money from this blog. And, you must know that affiliate marketing is one the best and largest method of monetizing your blog. Today, I&#8217;ve purchased a great plugin WP affiliate eliite for improving the affiliate marking income with the help of this blog. Let me show you how much money you can earn from affiliate marketing and how this plugin helps to make money for you.</p>
<p><span id="more-219"></span></p>
<h4>How much money a person can earn from affiliate marketing?</h4>
<p>Just look at the image below, you can see how much money a person can earn from affiliate marketing. Jeremy Shoemaker, a biggest name in Internet Marketing, made around $700,000 in a month from affiliate marketing. </p>
<pre><a rel="nofollow" target="_blank" href="http://www.shoemoney.com/gallery/v/misc/commission-junction.jpg.html?g2_imageViewsIndex=1"><img src="http://www.shoemoney.com/gallery/d/15370-2/commission-junction.jpg" border="0"/></a></pre>
<h4>A better plugin of WordPress for making money from blog</h4>
</p>
<p>With the help of WP affiliate eliite  plugin, you can easily convert the useful keyword of your blog post to affiliate links and start making more money from your blog. </p>
<pre>
<a href="http://roshanbha.wpaffelite.hop.clickbank.net" rel="nofollow"><img src="http://www.wpaffiliateelite.com/images/banners/468_60_monetize.jpg" border="0"/></a>
</pre>
</p>
<p>It just cost $47 to purchase that WP affiliate eliite plugin.Why don&#8217;t you start making money from blog from affiliate marketing with the help of this plugin. I think video speaks more than writing, check out the video from creator of WP affiliate eliite to know how this plugin helps you for making money from your blog.
</p>
<pre>
<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/OhLuFIb4vZc&#038;hl=en&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/OhLuFIb4vZc&#038;hl=en&#038;fs=1" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="344"></embed></object>
</pre>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=219&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/08/making-money-from-blog.html/feed</wfw:commentRss>
		<slash:comments>4</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>How to hide actual URL in the status bar of all browsers?</title>
		<link>http://roshanbh.com.np/2008/08/different-status-bar-text-hyperlink-mouseover.html</link>
		<comments>http://roshanbh.com.np/2008/08/different-status-bar-text-hyperlink-mouseover.html#comments</comments>
		<pubDate>Sat, 09 Aug 2008 17:50:46 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[how-to]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[status-bar]]></category>
		<category><![CDATA[url]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=210</guid>
		<description><![CDATA[Yesterday, Jacob mailed me and asked me how can I show different text or link in the status bar of browsers like Firefox or safari when mouse is over the link.He found the technique which only worked for IE but not for other browser but I&#8217;ve come up with a technique which works for all [...]]]></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%2Fdifferent-status-bar-text-hyperlink-mouseover.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F08%2Fdifferent-status-bar-text-hyperlink-mouseover.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, Jacob mailed me and asked me how can I show different text or link in the status bar of browsers like Firefox or safari when mouse is over the link.He found the technique which only worked for IE but not for other browser but I&#8217;ve come up with a technique which works for all browser. This kind of technique is quite useful if you want to hide the actual link in status bar of browsers and show the different URL instead of actual one.</p>
<p><span id="more-210"></span></p>
<h4>Old technique to display hide actual URL  in the status bar</h4>
<p style="text-align: justify;">If you search in google with the keyword <a href="http://www.google.com/search?q=change+status+bar+text&amp;ie=utf-8&amp;oe=utf-8&amp;aq=t&amp;rls=org.mozilla:en-US:official&amp;client=firefox-a" target="_blank">change status bar text </a>, you&#8217;ll find that many codes in different websites which are using <strong>window.status</strong> to change the text of the status bar while mouse is over the link. For example,</p>
<pre class="prettyprint" style="overflow:auto">&lt;a href="http://www.sell.com/?referrer=225" onMouseOver="window.status='http://www.sell.com';
return true" onMouseOut="window.status=''"&gt;Click here &lt;/a&gt;</pre>
<p style="text-align: justify;">The above link displays &#8220;http://www.sell.com&#8221; instead of &#8220;http://www.sell.com/?referrer=225&#8243; in the status bar when mouse is mover the hyperlink. But, the main drawback of above code is that it only works in Internet Explorer(IE) . It doesn&#8217;t change the status bar text of the link in any other browsers like &#8220;Firefox&#8221;, &#8220;Safari&#8221; etc.</p>
<h4>How to display diferent URL of links in status bar of Firefox , Safari etc ?</h4>
<p style="text-align: justify;">To change the satus bar text of the the link in firefox and safari you&#8217;ve to just use a small technique with the help of &#8220;<strong>href</strong>&#8221; and &#8220;<strong>Onclick</strong>&#8221; attribute of the hyperlink. Let&#8217;s look at the this technique step by step,</p>
<ol>
<li>First, make a javaScript function and define it exactly as below,
<pre class="prettyprint" style="overflow:auto">    &lt;script language="javascript" type="text/javascript"&gt;
     function redirect(URL)
     {
       document.location=URL;
       return false;
     }
    &lt;/script&gt;</pre>
</li>
<li>Now, define the hyperlink with the status bar text in <strong>href</strong> attribute and call the above function from <strong>onClick</strong> attribute of the link like below,
<pre class="prettyprint" style="overflow:auto">&lt;a href="http://www.sell.com" onclick="return
redirect('http://www.sell.com/?referrer=225');"&gt;Click here&lt;/a&gt;</pre>
</li>
</ol>
<p style="text-align: justify;">As we know the we see the text in status bar which is defined in the href attribute of the hyperlink. And when you click the link, code within <strong>onclick</strong> event of element is called. We&#8217;ve taken the benefit of this phenomenon to show the different text .</p>
<p style="text-align: justify;">But remember, this technique also have a drawback as it doesn&#8217;t work if JavaScript is diabled in the web browsers. In that case, the browers will be redirecteed to URL in the <strong>href</strong> attribute. If you worried about disabled JavaScript then you can check this post to knnow how to <a href="http://roshanbh.com.np/2008/04/how-to-know-handle-disabled-javascript.html">handle disabled JavaScript in browser</a>.</p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=210&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/08/different-status-bar-text-hyperlink-mouseover.html/feed</wfw:commentRss>
		<slash:comments>27</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>
		<item>
		<title>Tips to increase search engine traffic for your blog</title>
		<link>http://roshanbh.com.np/2008/07/tips-to-increase-search-engine-traffic-for-your-blog.html</link>
		<comments>http://roshanbh.com.np/2008/07/tips-to-increase-search-engine-traffic-for-your-blog.html#comments</comments>
		<pubDate>Fri, 11 Jul 2008 16:57:59 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[blogs]]></category>
		<category><![CDATA[seo]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=159</guid>
		<description><![CDATA[Which kind of traffic are you interested for your blog ? Is it traffic from social media or Is it traffic from search engine ? Which kind of traffic  is the better for your blog ? It must be one the which is consistent and regular and it is the traffic from search engine. It&#8217;s [...]]]></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%2Ftips-to-increase-search-engine-traffic-for-your-blog.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F07%2Ftips-to-increase-search-engine-traffic-for-your-blog.html&amp;source=roshanbh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Which kind of traffic are you interested for your blog ? Is it traffic from social media or Is it traffic from search engine ? Which kind of traffic  is the better for your blog ? It must be one the which is consistent and regular and it is the traffic from search engine. It&#8217;s been around 6 month when I started blogging in this domain. And nowadays, this blog is getting more than 1500 visits from the search engine.For detail,You can see the picture below directly taken from Google Analytics.<span id="more-159"></span></p>
<pre style="overflow:auto"><img class="alignnone size-full wp-image-160" title="se_visitor" src="http://roshanbh.com.np/wp-content/uploads/2008/07/se_visitor.gif" alt="" width="500" height="150" /></pre>
<p style="text-align: justify;">I think search engine traffic is the best traffic for your blog. Unlike social media traffic which are flashy, search engine traffic is consistent and regular. I&#8217;m so happy that this newborn blog is getting good amount of traffic from the search engine.</p>
<p><strong>Do you know tips to build search engine traffic for your blog ?  Do you want to how to build the search engine traffic for your blog ? </strong></p>
<p><strong> <a href="http://www.feedburner.com/fb/a/emailverifySubmit?feedId=1456759&amp;loc=en_US">Subscribe the RSS feed of this blog by email</a><br />
</strong></p>
<p style="text-align: justify;">Why might be surprising why I&#8217;m not posting the tips here and asking you subscribe to rss feed of this blog by email. The answer of this question is <a href="http://roshanbh.com.np/2008/07/help-me-to-become-the-first-blogging-idol.html">blogging Idol competition</a>. I&#8217;ve to increase RSS subscribers to win this competition. So, <a href="http://www.feedburner.com/fb/a/emailverifySubmit?feedId=1456759&amp;loc=en_US">Subscribe Now</a> and make me <a href="roshanbh.com.np/2008/07/help-me-to-become-the-first-blogging-idol.html">Blogging Idol</a> and get the tips to increase search engine traffic for your blog.</p>
<p style="text-align: justify;">I&#8217;ll email the tips to build search engline traffic for your blog in the first week of next week. Don&#8217;t miss the tips to build and increase the search engine traffic for your blog. <strong><a href="http://www.feedburner.com/fb/a/emailverifySubmit?feedId=1456759&amp;loc=en_US">Subscribe Now By Email</a></strong></p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=159&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/07/tips-to-increase-search-engine-traffic-for-your-blog.html/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>5 useful Google search tips you might now know</title>
		<link>http://roshanbh.com.np/2008/07/useful-google-search-tips.html</link>
		<comments>http://roshanbh.com.np/2008/07/useful-google-search-tips.html#comments</comments>
		<pubDate>Mon, 07 Jul 2008 11:35:19 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[how-to]]></category>
		<category><![CDATA[seo]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[search tips]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=149</guid>
		<description><![CDATA[I never knew that Google search can be used as calculator, currency converter or height and weight unit converter. Today I&#8217;ve discovered few Google search technique and I would like to share those technique with you. Look at the few useful search technique and you&#8217;ll get the answer &#8220;Why Google is the superior search engine?&#8221;. [...]]]></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%2Fuseful-google-search-tips.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F07%2Fuseful-google-search-tips.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 never knew that Google search can be used as calculator, currency converter or height and weight unit converter. Today I&#8217;ve discovered few Google search technique and I would like to share those technique with you. Look at the few useful search technique and you&#8217;ll  get the answer &#8220;Why Google is the superior search engine?&#8221;.</p>
<p><span id="more-149"></span></p>
<h4>Google search tips to find time of a city or country</h4>
<p>You can use &#8220;time&#8221; keyword followed by name of the city or country to find the current time of that country of city in Google search.</p>
<p style="text-align: justify;"><strong>Examples :</strong></p>
<p><span style="color: #000080;">time kathmandu<br />
time new york</span></p>
<pre style="overflow:auto"><img title="search-time" src="http://roshanbh.com.np/wp-content/uploads/2008/07/search-time.gif" alt="" /></pre>
<h4>Google search tips for Currency conversion</h4>
<p>you can use keyword like &#8220;1 USD in AUD&#8221; or &#8220;1 singapore money in japanese money&#8221; to find the currency difference using Google search.</p>
<p><strong>Examples :</strong></p>
<p><span style="color: #000080;">1 USD in thailand money<br />
1 singapore money in australian money</span></p>
<pre style="overflow:auto"><img class="alignnone size-full wp-image-152" title="search-currency" src="http://roshanbh.com.np/wp-content/uploads/2008/07/search-currency.gif" alt="" width="499" height="168" /></pre>
<h4>Google Search tips for Unit conversion</h4>
<p style="text-align: justify;">You can use the following kind of examples to convert the various unit of height and weight.</p>
<p style="text-align: justify;"><strong>Examples:</strong></p>
<p><span style="color: #000080;">1feet in meter<br />
1feet in cm<br />
1kg in pounds</span></p>
<pre style="overflow:auto"><img class="alignnone size-full wp-image-150" title="search-unit" src="http://roshanbh.com.np/wp-content/uploads/2008/07/search-unit.gif" alt="" width="500" height="179" /></pre>
<h4>Google search as calculator</h4>
<p style="text-align: justify;">You can enter math expression in Google search box to get the calculated result. For example, you can put the following expression in the Google search to find result of the calucation.</p>
<p style="text-align: justify;"><strong>Examples:</strong></p>
<p><span style="color: #000080;">(30+45)+5^2<br />
((30+45)+554)^2</span></p>
<pre style="overflow:auto"><img class="alignnone size-full wp-image-153" title="search-calculator" src="http://roshanbh.com.np/wp-content/uploads/2008/07/search-calculator.gif" alt="" width="500" height="205" /></pre>
<h4>Using Google search as Dictionary</h4>
<p style="text-align: justify;">You can use the Google as a dictionary as well. Just you have to type the keyword as &#8220;define:keyword&#8221; in google search box and you&#8217;ll get the meaning of that word.</p>
<p style="text-align: justify;"><strong>Examples:</strong></p>
<p><span style="color: #000080;">define:intelligent<br />
define:blog</span></p>
<pre style="overflow:auto"><img class="alignnone size-full wp-image-154" title="search-define" src="http://roshanbh.com.np/wp-content/uploads/2008/07/search-define.gif" alt="" width="500" height="280" /></pre>
<p style="text-align: justify;">
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=149&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/07/useful-google-search-tips.html/feed</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>How to control the case of characters using CSS?</title>
		<link>http://roshanbh.com.np/2008/07/control-character-case-css-text-transform.html</link>
		<comments>http://roshanbh.com.np/2008/07/control-character-case-css-text-transform.html#comments</comments>
		<pubDate>Sun, 06 Jul 2008 10:25:00 +0000</pubDate>
		<dc:creator>Roshan</dc:creator>
				<category><![CDATA[css]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[tips and technique]]></category>

		<guid isPermaLink="false">http://roshanbh.com.np/?p=148</guid>
		<description><![CDATA[How are you controlling the case of the characters in your project. Talking about me, I was using ucwords() function of PHP to control the case of the characters when required. Today, I come to know  two new property of CSS which controls the output of the case of the characters of the words. You [...]]]></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%2Fcontrol-character-case-css-text-transform.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Froshanbh.com.np%2F2008%2F07%2Fcontrol-character-case-css-text-transform.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;">How are you controlling the case of the characters in your project. Talking about me, I was using <a href="http://www.php.net/ucwords" target="_blank">ucwords()</a> function of PHP to control the case of the characters when required. Today, I  come to know  two new property of CSS which controls the output of the case of the characters of the words.</p>
<p style="text-align: justify;"><span id="more-148"></span><br />
You can control the characters using &#8220;text-transform&#8221; and &#8220;font-variant&#8221; property of the CSS to do this. You can change the characters of words to upper case, lower case and capitalize the first character of the word.Furthermore, you can use &#8220;font-variant&#8221; to display the font in small caps font i.e. all the lower case characters are converted into uppercase character but have small font size compared to text with character capitalized. Let&#8217;s see example,</p>
<h4>Example of using text-transform and font-variant</h4>
<pre class="prettyprint" style="overflow:auto ">&lt;span style="text-transform: capitalize"&gt;bill gates&lt;/span&gt; =&gt; <span style="text-transform: capitalize">bill gates</span>
&lt;span style="text-transform:lowercase"&gt;Bill Gates&lt;/span&gt; =&gt;  <span style="text-transform:lowercase">Bill Gates</span>
&lt;span style="text-transform: uppercase"&gt;bill gates&lt;/span&gt; =&gt; <span style="text-transform: uppercase">bill gates</span>
&lt;span style="font-variant:small-caps"&gt;Bill Gates&lt;/span&gt; =&gt; <span style="font-variant:small-caps">Bill Gates</span></pre>
<p style="text-align: justify;">As you can see clearly in the example how the character of case is changed using text-transform and font-variant property of CSS. I hope these property might be useful for those people who didn&#8217;t know about these properties. But &#8220;text-transform&#8221; should have had one more attribute to capitalize the first character of sentence, I&#8217;m missing that <img src='http://roshanbh.com.np/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' />  .</p>
<img src="http://roshanbh.com.np/?ak_action=api_record_view&id=148&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roshanbh.com.np/2008/07/control-character-case-css-text-transform.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 5/40 queries in 0.345 seconds using disk: basic
Object Caching 2188/2285 objects using disk: basic

Served from: roshanbh.com.np @ 2012-05-21 20:44:10 -->
