<?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>Blog de sati &#187; php</title>
	<atom:link href="http://satiro.es/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://satiro.es</link>
	<description>Blog</description>
	<lastBuildDate>Thu, 26 Aug 2010 13:57:46 +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>Saber el tiempo con PHP y Google</title>
		<link>http://satiro.es/2009/12/11/saber-el-tiempo-con-php-y-google/</link>
		<comments>http://satiro.es/2009/12/11/saber-el-tiempo-con-php-y-google/#comments</comments>
		<pubDate>Fri, 11 Dec 2009 17:20:57 +0000</pubDate>
		<dc:creator>Satiro</dc:creator>
				<category><![CDATA[informatica]]></category>
		<category><![CDATA[programacion]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xml2array]]></category>

		<guid isPermaLink="false">http://satiro.es/?p=461</guid>
		<description><![CDATA[Obteniendo los datos de Google Para obtener los datos del clima (condición, temperatura, humedad, vientos) de una ciudad determinada podemos acceder al siguiente URL. [code]http://www.google.com/ig/api?weather=ciudad&#38;hl=es[/code] Utilizando PHP para mostrar los datos Ahora que ya sabes como obtener los datos los cargamos utilizando la función file_get_contents y despues los convertimos en un array utilizando xml2array. Archivo]]></description>
			<content:encoded><![CDATA[<p><img src="http://satiro.es/wp-content/uploads/2009/12/google-weather-742058-300x182.gif" alt="google-weather-742058" width="300" height="182" class="alignleft size-medium wp-image-497" /><br />
Obteniendo los datos de Google<br />
Para obtener los datos del clima (condición, temperatura, humedad, vientos) de una ciudad determinada podemos acceder al siguiente URL.</p>
<p>[code]http://www.google.com/ig/api?weather=ciudad&amp;hl=es[/code]</p>
<p><span id="more-461"></span><br />
<div style='text-align:center;'>
<script type="text/javascript"><!--
google_ad_client = "pub-9839895588429684";
/* 468x60, creado 30/10/08 */
google_ad_slot = "3895526867";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div><br />
<strong>Utilizando PHP para mostrar los datos</strong><br />
Ahora que ya sabes como obtener los datos los cargamos utilizando la función <em>file_get_contents</em> y despues los convertimos en un array utilizando <a href="http://satiro.es/2009/12/xml2array-php-xml-parser/">xml2array</a>.</p>
<p><strong>Archivo <em>data.php</em></strong><br />
[php]<br />
require(&#8220;xml2array.php&#8221;);<br />
$url = &#8220;http://www.google.com/ig/api?weather=bilbao&amp;hl=es&#8221;;<br />
$contents = file_get_contents($url);<br />
$data = xml2array($contents);<br />
$weather_info = $data['xml_api_reply']['weather']['forecast_information'];<br />
$weather_current = $data['xml_api_reply']['weather']['current_conditions'];<br />
$weather_forecast = $data['xml_api_reply']['weather']['forecast_conditions'];<br />
[/php]</p>
<p>Como se puede ver, hemos obtenido los datos <em>forecast_information</em>, <em>current_conditions</em>, <em>forecast_conditions</em>. Estos nodos contienen los datos de la ciudad consultada, los datos actuales clima y la predicción del clima para los siguientes tres días.</p>
<p>El siguiente paso es mostrar los datos que hemos obtenido. Si mostramos los datos del clima actual tendríamos el siguiente código:</p>
<p><strong>Archivo <em>sample1.php</em></strong><br />
[php]</p>
<h3>Google Weather Demo </h3>
<div>
    <strong></strong><br />
    &lt; ?php echo &#039;<img src="http://www.google.com'.$weather_current['icon_attr']['data'].'" />&#8216;;?&gt;<br />
    Condición: <br />
    Temperatura:  &deg;C</p>
</div>
<p>[/php]<br />
Ver ejemplo <a href="http://satiro.es/samples/weather/sample1.php">aqui.</a></p>
<p>Mostramos el icono con el clima actual, los datos de la condición, temperatura y humedad.</p>
<p>También podemos mostrar las predicciones del clima para los siguientes días utilizando la variable <em>$weather_forecast</em> que contiene un array para ello escribimos:</p>
<p><strong>Archivo <em>sample2.php</em></strong><br />
[php]</p>
<div>
    &lt; ?php for ($i=0; $i</p>
<div>
        <br />
        &lt; ?php echo &#039;<img src="http://www.google.com'.$foreday['icon']['attr']['data'].'" />&#8216;;?&gt;<br />
        <br />
        &deg;C |<br />
        &deg;C</p></div>
</div>
<p>[/php]<br />
Ver ejemplo <a href="http://satiro.es/samples/weather/sample2.php">aqui</a>.<br />
Agregando CSS y un formulario de búsqueda podemos obtener excelentes resultados, solo depende de nuestra imaginación.</p>
]]></content:encoded>
			<wfw:commentRss>http://satiro.es/2009/12/11/saber-el-tiempo-con-php-y-google/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>xml2array: PHP XML Parser</title>
		<link>http://satiro.es/2009/12/11/xml2array-php-xml-parser/</link>
		<comments>http://satiro.es/2009/12/11/xml2array-php-xml-parser/#comments</comments>
		<pubDate>Fri, 11 Dec 2009 16:26:31 +0000</pubDate>
		<dc:creator>Satiro</dc:creator>
				<category><![CDATA[informatica]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://satiro.es/?p=432</guid>
		<description><![CDATA[xml2array es un función hecha en PHP que nos permitirá convertir datos en formato XML a un array. Obteniendo la función Puedes descargar esta función desde la web del autor de xml2array y guardar el código en un archivo llamado xml2array.php Utilizando xml2array Para utilizar esta función, pasamos como parámetro una cadena que contiene el]]></description>
			<content:encoded><![CDATA[<p><img src="http://satiro.es/wp-content/uploads/2009/12/xml2array.png" alt="xml2array" width="200" height="97" class="alignleft size-full wp-image-457" /><br />
<a href="http://www.bin-co.com/php/scripts/xml2array/">xml2array</a> es un función hecha en PHP que nos permitirá convertir datos en formato XML a un array.</p>
<p><span id="more-432"></span><br />
<div style='text-align:center;'>
<script type="text/javascript"><!--
google_ad_client = "pub-9839895588429684";
/* 468x60, creado 30/10/08 */
google_ad_slot = "3895526867";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div><br />
<strong>Obteniendo la función</strong><br />
Puedes descargar esta función desde la web del autor de <a href="http://www.bin-co.com/php/scripts/xml2array/">xml2array</a> y guardar el código en un archivo llamado <em>xml2array.php</em></p>
<p><strong>Utilizando xml2array</strong><br />
Para utilizar esta función, pasamos como parámetro una cadena que contiene el XML y lo retornará en un array.</p>
<p><strong>Archivo <em>demo.xml</em></strong><br />
[xml]</p>
<p>          nokia<br />
          siemens<br />
          samsung<br />
          lg</p>
<p>[/xml]</p>
<p><strong>Archivo <em>sample.php</em></strong><br />
[php]<br />
require(&#8220;xml2array.php&#8221;);<br />
$contents = file_get_contents(&#8216;demo.xml&#8217;);<br />
$result = xml2array($contents);<br />
print_r($result);<br />
[/php]</p>
<p>El resultado de este código es:<br />
[php]<br />
      Array<br />
      (<br />
          [lang] =&gt; Array<br />
              (<br />
                  [attr] =&gt; Array<br />
                      (<br />
                          [type] =&gt; moviles<br />
                      )<br />
                  [name] =&gt; Array<br />
                      (<br />
                          [0] =&gt; Array<br />
                              (<br />
                                  [value] =&gt; nokia<br />
                                  [attr] =&gt; Array ( [id] =&gt; 1 )<br />
                              )<br />
                          [1] =&gt; Array<br />
                              (<br />
                                  [value] =&gt; siemens<br />
                                  [attr] =&gt; Array ( [id] =&gt; 2 )<br />
                              )<br />
                          [2] =&gt; Array<br />
                              (<br />
                                  [value] =&gt; samsung<br />
                                  [attr] =&gt; Array ( [id] =&gt; 3 )<br />
                              )<br />
                          [3] =&gt; Array<br />
                              (<br />
                                  [value] =&gt; lg<br />
                                  [attr] =&gt; Array ( [id] =&gt; 4 )<br />
                              )<br />
                      )<br />
              )<br />
      )<br />
[/php]</p>
<p>Entonces si deseamos conocer cuales son los valores de los móviles con sus respectivos identificadores, haríamos lo siguiente:<br />
[php]<br />
require(&#8220;xml2array.php&#8221;);<br />
$contents = file_get_contents(&#8216;demo.xml&#8217;);<br />
$result = xml2array($contents);<br />
$langs = $result['lang']['name'];<br />
for ($i=0; $i&lt; count ($langs); $i++) {<br />
    echo $langs[$i][&#039;attr&#039;][&#039;id&#039;].&quot; &#8211; &quot;.$langs[$i][&#039;value&#039;];<br />
}<br />
[/php]</p>
<p>Una vez que esta convertido el XML en array es sencillo recorrer la información contenida en el.</p>
<p>Actualizado</p>
<p><a href="http://satiro.es/samples/xml2array.txt">Código fuente de xml2array.php</p>
]]></content:encoded>
			<wfw:commentRss>http://satiro.es/2009/12/11/xml2array-php-xml-parser/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
