<?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>Bagesh Singh&#039;s Blog -  A blog about PHP, Ajax, JavaScript, CSS, Web 2.0 and Web Development &#187; api</title>
	<atom:link href="http://www.bageshsingh.com/bagesh-blog/tag/api/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bageshsingh.com/bagesh-blog</link>
	<description>The shortest distance to a software &#38; web solutions</description>
	<lastBuildDate>Thu, 09 Sep 2010 11:44:47 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Getting country , city name from IP address in PHP</title>
		<link>http://www.bageshsingh.com/bagesh-blog/2010/03/getting-country-city-name-from-ip-address-in-php-2/</link>
		<comments>http://www.bageshsingh.com/bagesh-blog/2010/03/getting-country-city-name-from-ip-address-in-php-2/#comments</comments>
		<pubDate>Tue, 16 Mar 2010 11:28:52 +0000</pubDate>
		<dc:creator>Bagesh Singh</dc:creator>
				<category><![CDATA[web services]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.bageshsingh.com/bagesh-blog/2010/03/getting-country-city-name-from-ip-address-in-php-2/</guid>
		<description><![CDATA[Yesterday,  miaki asked me how can we get the  country name from the IP address in PHP. Today, I’ve come up with the  answer of this question. I’ve used the API from hostip.info to fetch the  country name , city name and country code from the given IP address.  I’ve [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday,  miaki asked me how can we get the  country name from the IP address in PHP. Today, I’ve come up with the  answer of this question. I’ve used the API from hostip.info to fetch the  country name , city name and country code from the given IP address.  I’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>
<h4>Function to return country, city name from IP address in PHP</h4>
<pre>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><a href="http://roshanbh.com.np/codes/country-ip.phps">Download Source Code</a></p>
<p>As you can see, I’ve documented all the  PHP code and I don’t think I need explain anymore about that code. Just  notice that, this function returns the array containg three key elements  “country” , “city” and “country_code”. Each elements have the value of  city, country and country code.</p>
<p>Now, look the the how we can use the  above function in PHP,</p>
<pre>$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>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 real  IP address in PHP.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bageshsingh.com/bagesh-blog/2010/03/getting-country-city-name-from-ip-address-in-php-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Web Services and PHP – SOAP vs XML-RPC vs REST</title>
		<link>http://www.bageshsingh.com/bagesh-blog/2010/03/web-services-and-php-%e2%80%93-soap-vs-xml-rpc-vs-rest-2/</link>
		<comments>http://www.bageshsingh.com/bagesh-blog/2010/03/web-services-and-php-%e2%80%93-soap-vs-xml-rpc-vs-rest-2/#comments</comments>
		<pubDate>Tue, 16 Mar 2010 11:28:02 +0000</pubDate>
		<dc:creator>Bagesh Singh</dc:creator>
				<category><![CDATA[Home]]></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://www.bageshsingh.com/bagesh-blog/?p=217</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 [...]]]></description>
			<content:encoded><![CDATA[<h4>What is web services?</h4>
<p>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’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>There are different method for providing  web services but the most common are SOAP, XML-RPC and REST .</p>
<h4>SOAP</h4>
<p>SOAP 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 SOAP  Message articture from here. SOAP is widely criticized for it’s  design complexity.</p>
<p>In PHP 5, there is built-in extension  for the providing and consuming web services. But, I personally prefer Nusoap toolkit of PHP for providing and consuming web services using SOAP in  PHP.</p>
<h4>XML-RPC</h4>
<p>XML-RPC  (remote procedure call) another way of providing and consuming web  services. It uses XML to encode and decode the remote procedure call  along with it’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="http://roshanbh.com.np/2008/07/www.xmlrpc.com">www.xmlrpc.com </a> to know more about XML-RPC.</p>
<p>In PHP, there is extension which contain various  functions for facilating XML-RPC request and response. But the  functions xmlrpc_encode_request() and xmlrpc_decode_request() available in PHP is very useful for when it comes to encode and decode  XML-RPC request and response.</p>
<p>I’ve built  Indian Currency Converter using XML-RPC web services  provided by <a href="http://foxrate.org/">foxrate.org</a>.</p>
<h4>REST</h4>
<p>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><strong>Resources</strong> are  application’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>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>Talking about  PHP, the format of  information(representation) returned can be in XML, JSON or even in HTML  format. DOM functions,  SimpleXML functions and JSON functions comes  handy when you are handling RESTful interfaces in PHP.</p>
<p>I also want to know your view. Please  participate in the poll below.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bageshsingh.com/bagesh-blog/2010/03/web-services-and-php-%e2%80%93-soap-vs-xml-rpc-vs-rest-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting technorati ranking in PHP without using their API</title>
		<link>http://www.bageshsingh.com/bagesh-blog/2010/03/getting-technorati-ranking-in-php-without-using-their-api/</link>
		<comments>http://www.bageshsingh.com/bagesh-blog/2010/03/getting-technorati-ranking-in-php-without-using-their-api/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 16:19:55 +0000</pubDate>
		<dc:creator>Bagesh Singh</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[technorati]]></category>

		<guid isPermaLink="false">http://www.bageshsingh.com/bagesh-blog/?p=113</guid>
		<description><![CDATA[Today, I was going through the Technorati API to find the rank of the blog using PHP. Those who doesn’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[<p>Today, I was going through the Technorati API to find the rank of the blog using PHP. Those who doesn’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>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’ve used the following  URL of technorati</p>
<p>“http://www.technorati.com/blogs/&lt;blog-url&gt;”</p>
<p>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>&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&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><strong><a href="http://roshanbh.com.np/codes/technorati.phps" target="_blank">Download Source Code</a></strong></p>
<p>As you can above, I’ve used file_get_contens() function of PHP to get the content from Technorati. The rank of the blog if found under the division “&lt;div class=”rank”&gt;&lt;/div&gt;” in that page of Technorati, you can verify it by viewing the source of that page. After that, I’ve used few regular expression to find the ranking of the blog in PHP.</p>
<p>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>
]]></content:encoded>
			<wfw:commentRss>http://www.bageshsingh.com/bagesh-blog/2010/03/getting-technorati-ranking-in-php-without-using-their-api/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Getting country , city name from IP address in PHP</title>
		<link>http://www.bageshsingh.com/bagesh-blog/2010/03/getting-country-city-name-from-ip-address-in-php/</link>
		<comments>http://www.bageshsingh.com/bagesh-blog/2010/03/getting-country-city-name-from-ip-address-in-php/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 16:19:00 +0000</pubDate>
		<dc:creator>Bagesh Singh</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[web services]]></category>

		<guid isPermaLink="false">http://www.bageshsingh.com/bagesh-blog/?p=111</guid>
		<description><![CDATA[Yesterday,  miaki asked me how can we get the country name from the IP address in PHP. Today, I’ve come up with the answer of this question. I’ve used the API from hostip.info to fetch the country name , city name and country code from the given IP address. I’ve mad this function in [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday,  miaki asked me how can we get the country name from the IP address in PHP. Today, I’ve come up with the answer of this question. I’ve used the API from hostip.info to fetch the country name , city name and country code from the given IP address. I’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>
<h4>Function to return country, city name from IP address in PHP</h4>
<pre>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><a href="http://roshanbh.com.np/codes/country-ip.phps">Download Source Code</a></p>
<p>As you can see, I’ve documented all the PHP code and I don’t think I need explain anymore about that code. Just notice that, this function returns the array containg three key elements “country” , “city” and “country_code”. Each elements have the value of city, country and country code.</p>
<p>Now, look the the how we can use the above function in PHP,</p>
<pre>$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>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 real IP address in PHP.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bageshsingh.com/bagesh-blog/2010/03/getting-country-city-name-from-ip-address-in-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Web Services and PHP – SOAP vs XML-RPC vs REST</title>
		<link>http://www.bageshsingh.com/bagesh-blog/2010/03/web-services-and-php-%e2%80%93-soap-vs-xml-rpc-vs-rest/</link>
		<comments>http://www.bageshsingh.com/bagesh-blog/2010/03/web-services-and-php-%e2%80%93-soap-vs-xml-rpc-vs-rest/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 16:17:20 +0000</pubDate>
		<dc:creator>Bagesh Singh</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[SOAP]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[XML-RPC]]></category>

		<guid isPermaLink="false">http://www.bageshsingh.com/bagesh-blog/?p=109</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 recent [...]]]></description>
			<content:encoded><![CDATA[<h4>What is web services?</h4>
<p>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’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>There are different method for providing web services but the most common are SOAP, XML-RPC and REST .</p>
<h4>SOAP</h4>
<p>SOAP 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 SOAP Message articture from here. SOAP is widely criticized for it’s design complexity.</p>
<p>In PHP 5, there is built-in extension for the providing and consuming web services. But, I personally prefer Nusoap toolkit of PHP for providing and consuming web services using SOAP in PHP.</p>
<h4>XML-RPC</h4>
<p>XML-RPC (remote procedure call) another way of providing and consuming web services. It uses XML to encode and decode the remote procedure call along with it’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 www.xmlrpc.com  to know more about XML-RPC.</p>
<p>In PHP, there is extension which contain various functions for facilating XML-RPC request and response. But the functions xmlrpc_encode_request() and xmlrpc_decode_request() available in PHP is very useful for when it comes to encode and decode XML-RPC request and response.</p>
<p>I’ve built  Nepali Currency Converter using XML-RPC web services provided by foxrate.org.</p>
<h4>REST</h4>
<p>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><strong>Resources</strong> are application’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>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>Talking about  PHP, the format of information(representation) returned can be in XML, JSON or even in HTML format. DOM functions, SimpleXML functions and JSON functions comes handy when you are handling RESTful interfaces in PHP.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bageshsingh.com/bagesh-blog/2010/03/web-services-and-php-%e2%80%93-soap-vs-xml-rpc-vs-rest/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
