<?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>JQuery, PHP, html, design... // arnaud-k : un blog de geek &#187; api</title>
	<atom:link href="http://blog.arnaud-k.fr/tag/api/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.arnaud-k.fr</link>
	<description>Le blog JQuery, PHP, html, design… // un blog de geek</description>
	<lastBuildDate>Wed, 08 Sep 2010 20:12:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Tutorial API Youtube : rechercher et afficher des vidéos (PHP et JQuery)</title>
		<link>http://blog.arnaud-k.fr/2009/developpement-web/cat-jquery/tutorial-api-youtube-rechercher-et-afficher-des-videos-php-et-jquery/</link>
		<comments>http://blog.arnaud-k.fr/2009/developpement-web/cat-jquery/tutorial-api-youtube-rechercher-et-afficher-des-videos-php-et-jquery/#comments</comments>
		<pubDate>Fri, 05 Jun 2009 11:34:55 +0000</pubDate>
		<dc:creator>arnaud</dc:creator>
				<category><![CDATA[JQuery]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[API youtube]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.arnaud-k.fr/?p=623</guid>
		<description><![CDATA[J&#8217;ai eu très récemment l&#8217;occasion de travailler sur l&#8217;API de Youtube. Cette API, évidemment fourni par Google, est très complète et peut permettre beaucoup d&#8217;interactions avec Youtube (recherche et visionnage de vidéos, upload, login, &#8230;). La documentation fourni par Google est, comment dire, un peu fouilli et pas très claire. Je vais néanmoins te partager [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.arnaud-k.fr%2F2009%2Fdeveloppement-web%2Fcat-jquery%2Ftutorial-api-youtube-rechercher-et-afficher-des-videos-php-et-jquery%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.arnaud-k.fr%2F2009%2Fdeveloppement-web%2Fcat-jquery%2Ftutorial-api-youtube-rechercher-et-afficher-des-videos-php-et-jquery%2F&amp;source=arnaudk&amp;style=compact&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p><img class="aligncenter size-full wp-image-624" title="Tutoriel API Youtube" src="http://blog.arnaud-k.fr/wp-content/uploads/2009/06/youtube.png" alt="Tutoriel API Youtube" width="600" height="200" /></p>
<p>J&#8217;ai eu très récemment l&#8217;occasion de travailler sur l&#8217;<strong>API de Youtube</strong>. Cette API, évidemment fourni par Google, est très complète et peut permettre beaucoup d&#8217;interactions avec Youtube (recherche et visionnage de vidéos, upload, login, &#8230;). La documentation fourni par Google est, comment dire, un peu fouilli et pas très claire.</p>
<p>Je vais néanmoins te partager mes découvertes en proposant un tutorial pour rechercher des vidéos sur Youtube, afficher les résultats (sous forme de miniature) et lire les vidéos.</p>
<p><a href="http://www.awelty.fr/arnaud-k/youtube/" class="demo" title="Demo Api Youtube">Demo Api Youtube</a></p>
<p>Comme d&#8217;hab, j&#8217;ai préparé une <strong><a href="http://www.awelty.fr/arnaud-k/youtube/">démo de ce tutorial</a></strong> (démo hébergée chez mon employeur car mon hébergement 1&amp;1 n&#8217;est pas PHP 5). Comme c&#8217;est du PHP, j&#8217;ai également prévu le <a href="http://blog.arnaud-k.fr/youtube/APIyoutube.zip">téléchargement</a><strong> des sources de la démo</strong>.</p>
<p>Tout d&#8217;abord il est absolument nécessaire d&#8217;avoir <strong>un serveur PHP 5.2</strong> au minimum. Il faut également télécharger un standalone du framework PHP zend, <a href="http://framework.zend.com/download/gdata">GData</a> qui contient les fichiers nécessaires au fonctionnement de l&#8217;API. Enfin pour juste effectuer des recherches et afficher des vidéos, il n&#8217;est pas nécessaire d&#8217;avoir une key pour l&#8217;API Youtube.</p>
<p>Dans le .zip de GData, il y a un dossier &laquo;&nbsp;librairy&nbsp;&raquo; dans lequel on retrouve un dossier &laquo;&nbsp;Zend&nbsp;&raquo;, c&#8217;est celui-là qu&#8217;il faut uploader à la racine de ton site.</p>
<p><span style="color:#ffa800; font-size:1.3em; font-weight:bold">Jetons maintenant un oeil au code :</span></p>
<p>Le principe est le suivant : on fait une requête (en utlisant les objets mis à disposition par l&#8217;API) et on récupère et on traite les informations à partir du flux XML retourné (<a href="http://code.google.com/intl/fr/apis/youtube/2.0/developers_guide_php.html#Video_Entry_Contents">voir la liste des infos disponible</a>).</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'Zend/Gdata/YouTube.php'</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// on charge la librairie YouTube</span>
&nbsp;
<span style="color: #000088;">$yt</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Gdata_YouTube<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// on initialise l'objet Youtube</span>
<span style="color: #000088;">$yt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setMajorProtocolVersion</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$yt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">newVideoQuery</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setOrderBy</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'relevance'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// les vidéos sont classées par pertinence</span>
<span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setTime</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'all_time'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// on souhaite afficher les vidéos qui ont été ajoutées n'importe quand</span>
<span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setVideoQuery</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;fat freddy's drop&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// on définit la recherche</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// on récupère un flux XML avec la liste des vidéos</span>
<span style="color: #000088;">$flux</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$yt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getVideoFeed</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getQueryUrl</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// on affiche les miniatures </span>
get_results<span style="color: #009900;">&#40;</span><span style="color: #000088;">$flux</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>La fonction get_results() est une fonction permettant de parcourir le flux XML des résultats pour le traitement des informations. Cette fonction appelle elle-même la fonction afficheMiniature() qui permet d&#8217;afficher les miniatures des vidéos. Ici, je stoppe le listing des résultats à 6, mais on peut en afficher jusqu&#8217;à 25.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/******** FONCTIONS POUR L'API YOUTUBE ********/</span>
<span style="color: #666666; font-style: italic;">// On recupère l'url du player flash et une miniature de la video (format 120*90)</span>
<span style="color: #666666; font-style: italic;">// et on affiche la miniature en mettant l'url du player en id (pour le récupérer avec JQuery après)</span>
<span style="color: #000000; font-weight: bold;">function</span> afficheMiniature<span style="color: #009900;">&#40;</span><span style="color: #000088;">$video</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$miniature</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$video</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getVideoThumbnails</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;img class=&quot;videoThumb&quot; id=&quot;'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$video</span><span style="color: #339933;">-/&gt;</span>getFlashPlayerUrl<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; src=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$miniature</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; alt=&quot;&quot; /&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// fonction permettant de parcourir les vidéos provenant d'un flux</span>
<span style="color: #000000; font-weight: bold;">function</span> get_results<span style="color: #009900;">&#40;</span><span style="color: #000088;">$videos</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	    <span style="color: #000088;">$count</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
	    <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$videos</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$video</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		afficheMiniature<span style="color: #009900;">&#40;</span><span style="color: #000088;">$video</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$count</span><span style="color: #339933;">==</span><span style="color: #cc66cc;">6</span><span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$count</span><span style="color: #339933;">++;</span>
	    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Enfin, j&#8217;ai ajouté un petit code JQuery pour permettre l&#8217;affichage d&#8217;un seul player flash (s&#8217;il y en a plusieurs sur une page, celle-ci peut galérer un peu) et de changer la vidéo lorsque l&#8217;on clique sur une miniature. Par défaut (au chargement de la page) on affiche la première vidéo.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #006600; font-style: italic;">/* ##########
		AFFICHAGE DYNAMIQUE DES VIDEOS
	########## */</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#lectureVideo&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #006600; font-style: italic;">// afficher une video au chargement de la page si le div ayant pour id lectureVideo</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> urlVideo <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;img.videoThumb:first&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;id&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#lectureVideo&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;object width=&quot;360&quot; height=&quot;300&quot;&gt;&lt;param name=&quot;movie&quot; value=&quot;'</span><span style="color: #339933;">+</span>urlVideo<span style="color: #339933;">+</span><span style="color: #3366CC;">'&amp;color1=0x2193bd&amp;color2=0x2193bd&quot;&gt;&lt;/param&gt;&lt;param name=&quot;allowFullScreen&quot; value=&quot;true&quot;&gt;&lt;/param&gt;&lt;param name=&quot;allowscriptaccess&quot; value=&quot;always&quot;&gt;&lt;/param&gt;&lt;embed src=&quot;'</span><span style="color: #339933;">+</span>urlVideo<span style="color: #339933;">+</span><span style="color: #3366CC;">'&amp;color1=0x2193bd&amp;color2=0x2193bd&quot; type=&quot;application/x-shockwave-flash&quot; allowscriptaccess=&quot;always&quot; allowfullscreen=&quot;true&quot; width=&quot;360&quot; height=&quot;300&quot;&gt;&lt;/embed&gt;&lt;/object&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;img.videoThumb&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// si on clique sur une miniature on affiche la vidéo dans le bloc ayant pour id &quot;lectureVideo&quot;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#lectureVideo&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;object width=&quot;360&quot; height=&quot;300&quot;&gt;&lt;param name=&quot;movie&quot; value=&quot;'</span><span style="color: #339933;">+</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;id&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'&amp;color1=0x2193bd&amp;color2=0x2193bd&quot;&gt;&lt;/param&gt;&lt;param name=&quot;allowFullScreen&quot; value=&quot;true&quot;&gt;&lt;/param&gt;&lt;param name=&quot;allowscriptaccess&quot; value=&quot;always&quot;&gt;&lt;/param&gt;&lt;embed src=&quot;'</span><span style="color: #339933;">+</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;id&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'&amp;color1=0x2193bd&amp;color2=0x2193bd&quot; type=&quot;application/x-shockwave-flash&quot; allowscriptaccess=&quot;always&quot; allowfullscreen=&quot;true&quot; width=&quot;360&quot; height=&quot;300&quot;&gt;&lt;/embed&gt;&lt;/object&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Pour voir la structure HTML que j&#8217;ai utilisé, je t&#8217;invite à regarder le code de la démo (CTRL+U sous firefox). C&#8217;est à toi de jouer maintenant ! <img src='http://blog.arnaud-k.fr/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>Toute la code officielle est <a href="http://code.google.com/intl/fr-FR/apis/youtube/overview.html">disponible ici</a>.</p>


<p>Sur le même sujet :<ol><li><a href='http://blog.arnaud-k.fr/2009/developpement-web/cat-jquery/tutorial-plugin-jquery-delectable-pour-afficher-les-derniers-bookmarks-delicious/' rel='bookmark' title='Permanent Link: Tutorial plugin JQuery : Delectable pour afficher les derniers bookmarks Delicious'>Tutorial plugin JQuery : Delectable pour afficher les derniers bookmarks Delicious</a></li>
<li><a href='http://blog.arnaud-k.fr/2010/hors-sujet/la-video-du-jour-ok-go-this-too-shall-pass/' rel='bookmark' title='Permanent Link: La vidéo du jour : OK Go &#8211; This Too Shall Pass'>La vidéo du jour : OK Go &#8211; This Too Shall Pass</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.arnaud-k.fr/2009/developpement-web/cat-jquery/tutorial-api-youtube-rechercher-et-afficher-des-videos-php-et-jquery/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>API géolocalisation adresse IP avec iplocationtools</title>
		<link>http://blog.arnaud-k.fr/2009/developpement-web/cat-php/api-geolocalisation-dadresse-ip-avec-iplocationtools/</link>
		<comments>http://blog.arnaud-k.fr/2009/developpement-web/cat-php/api-geolocalisation-dadresse-ip-avec-iplocationtools/#comments</comments>
		<pubDate>Thu, 14 May 2009 11:53:19 +0000</pubDate>
		<dc:creator>arnaud</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[geolocalisation]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.arnaud-k.fr/?p=524</guid>
		<description><![CDATA[J&#8217;avais un peu étudié les différentes solutions d&#8217;API de géolocalisation d&#8217;adresse IP il y a quelques temps. J&#8217;étais sur cette solution tout simple : iplocationtools. Iplocationtools est une API que l&#8217;on peut appeler directement en PHP (voir le code ci-dessous). Cela crée un fichier XML contenant toutes les infos nécessaires à la géolocalisation (pays, region, [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.arnaud-k.fr%2F2009%2Fdeveloppement-web%2Fcat-php%2Fapi-geolocalisation-dadresse-ip-avec-iplocationtools%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.arnaud-k.fr%2F2009%2Fdeveloppement-web%2Fcat-php%2Fapi-geolocalisation-dadresse-ip-avec-iplocationtools%2F&amp;source=arnaudk&amp;style=compact&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p><img class="aligncenter size-full wp-image-525" title="geolocalisation d'adresse ip" src="http://blog.arnaud-k.fr/wp-content/uploads/2009/05/geoloc.png" alt="geolocalisation d'adresse ip" width="600" height="200" /></p>
<p>J&#8217;avais un peu étudié les différentes solutions d&#8217;<strong>API de géolocalisation d&#8217;adresse IP</strong> il y a quelques temps. J&#8217;étais sur cette solution tout simple : <a href="http://iplocationtools.com/">iplocationtools</a>.</p>
<p>Iplocationtools est une API que l&#8217;on peut appeler directement en PHP (voir le code ci-dessous). Cela crée un fichier XML contenant toutes les infos nécessaires à la géolocalisation (<strong>pays, region, ville, latitude et longitude </strong>principalement). Il ne reste plus qu&#8217;à le parser.</p>
<p>Code à intégrer pour appeler l&#8217;API :</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> locateIp<span style="color: #009900;">&#40;</span><span style="color: #000088;">$ip</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$d</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://www.iplocationtools.com/ip_query.php?ip=<span style="color: #006699; font-weight: bold;">$ip</span>&amp;output=xml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// on charge l'api</span>
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$d</span><span style="color: #009900;">&#41;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Failed to open connection</span>
&nbsp;
    <span style="color: #000088;">$answer</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SimpleXMLElement<span style="color: #009900;">&#40;</span><span style="color: #000088;">$d</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$answer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Status</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'OK'</span><span style="color: #009900;">&#41;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Invalid status code</span>
&nbsp;
        <span style="color: #000088;">$country_code</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$answer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CountryCode</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$country_name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$answer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CountryName</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$region_name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$answer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">RegionName</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$city</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$answer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">City</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$zippostalcode</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$answer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ZipPostalCode</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$latitude</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$answer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Latitude</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$longitude</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$answer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Longitude</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">//Return the data as an array</span>
    <span style="color: #b1b100;">return</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'latitude'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$latitude</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'longitude'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$longitude</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'zippostalcode'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$zippostalcode</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'city'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$city</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'region_name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$region_name</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'country_name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$country_name</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'country_code'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$country_code</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'ip'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$ip</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>A toi de jouer maintenant !</p>


<p>Pas encore de billet sur le même sujet !</p>]]></content:encoded>
			<wfw:commentRss>http://blog.arnaud-k.fr/2009/developpement-web/cat-php/api-geolocalisation-dadresse-ip-avec-iplocationtools/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
