<?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>Cristián Pérez &#187; php</title>
	<atom:link href="http://www.cristianperez.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cristianperez.com</link>
	<description>Experimentando la vida</description>
	<lastBuildDate>Tue, 25 Jan 2011 04:06:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Generador de ID continuas al estilo URL corta</title>
		<link>http://www.cristianperez.com/2010/03/23/generador-de-id-continuas-al-estilo-url-corta/</link>
		<comments>http://www.cristianperez.com/2010/03/23/generador-de-id-continuas-al-estilo-url-corta/#comments</comments>
		<pubDate>Tue, 23 Mar 2010 03:21:11 +0000</pubDate>
		<dc:creator>Cristián</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[Recursos]]></category>

		<guid isPermaLink="false">http://www.cristianperez.com/?p=293</guid>
		<description><![CDATA[Bueno&#8230;. si&#8230; es bueno para matar al Alzheimer
Bajo la duda de un amigo acerca de como generar numeros de ID cortos para utilizar en un servicio acortador de url&#8217;s se me ocurrio utilizar letras mayusculas y minusculas para aumentar la cantidad de posibles valores en una posicion de la cadena, ya que  [...]]]></description>
			<content:encoded><![CDATA[<p>Bueno&#8230;. si&#8230; es bueno para matar al <a href="http://es.wikipedia.org/wiki/Enfermedad_de_Alzheimer">Alzheimer</a></p>
<p>Bajo la duda de un amigo acerca de como generar numeros de ID cortos para utilizar en un servicio acortador de url&#8217;s se me ocurrio utilizar letras mayusculas y minusculas para aumentar la cantidad de posibles valores en una posicion de la cadena, ya que los numeros solo permitian 10 posibilidades (0-9) y la cadena se alargaria rapidamente.<span id="more-293"></span><br />
De esta manera puedo generar cadenas al estilo &#8220;a1D2&#8243;, y producir su valor consecutivo, que quedaria asi &#8220;a1D3&#8243;, asi hasta llegar al &#8220;a1D9&#8243; y luego comenzar con &#8220;a1DA&#8221;, asi hasta terminar las mayusculas, y minusculas. Una vez sucedido esto, el movimiento es similar al de un cuenta kilometros. y el valor quedaria asi &#8220;a1F0&#8243; y podriamos seguir!..</p>
<p>Ahora bien, la funcion puede generar el siguiente id, partiendo desde cualquier anterior!..<br />
Por ejemplo, si le ingresaramos el ID &#8220;0&#8243; nos devolveria 1 y si ingresaramos el id &#8220;0000&#8243; nos devolveria 0001, tambien si pusieramos &#8220;ABCD&#8221; nos devolveria &#8220;ABCE&#8221;.</p>
<p>La declaración de la funcion es la siguiente.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * Genera la cadena siguiente a una cadena de caracteres alphanumericos no simbolicos ingresada
 * 
 * @author Cristián Pérez
 * @param string $current
 * @return string
 * 
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> getNextKey<span style="color: #009900;">&#40;</span><span style="color: #000088;">$current</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$chars</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$current</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$chars</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ord</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$current</span><span style="color: #339933;">,</span> <span style="color: #000088;">$i</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000088;">$ci</span> <span style="color: #339933;">=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$chars</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$ci</span><span style="color: #339933;">;;</span><span style="color: #000088;">$i</span><span style="color: #339933;">--</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$chars</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&gt;=</span> <span style="color: #cc66cc;">48</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$chars</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">57</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$chars</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&gt;=</span> <span style="color: #cc66cc;">65</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$chars</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">90</span><span style="color: #009900;">&#41;</span> xor <span style="color: #009900;">&#40;</span><span style="color: #000088;">$chars</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&gt;=</span> <span style="color: #cc66cc;">97</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$chars</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">122</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #339933;">++</span><span style="color: #000088;">$chars</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$chars</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">57</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$chars</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">65</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$chars</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">90</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$chars</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">97</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$chars</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">122</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$chars</span> <span style="color: #b1b100;">as</span> <span style="color: #339933;">&amp;</span><span style="color: #000088;">$char</span><span style="color: #009900;">&#41;</span>
				<span style="color: #009900;">&#123;</span>
					<span style="color: #000088;">$char</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">48</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
&nbsp;
				<span style="color: #000088;">$chars</span><span style="color: #009900;">&#91;</span><span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$chars</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">48</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">else</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$chars</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">48</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$chars</span> <span style="color: #b1b100;">as</span> <span style="color: #339933;">&amp;</span><span style="color: #000088;">$char</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$char</span> <span style="color: #339933;">=</span> <span style="color: #990000;">chr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$char</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$chars</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Un ejemplo practico para que entiendan como funciona es el siguiente, el cual pueden copiar y pegar en un archivo nuevo para que lo prueben.
</pre>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$form</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;form action=&quot;&quot; method=&quot;post&quot;&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$form</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;input type=&quot;text&quot; name=&quot;currentID&quot; value=&quot;%s&quot; /&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$form</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;input type=&quot;submit&quot; value=&quot;Siguiente ID&quot; /&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$form</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;/form&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #990000;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$form</span><span style="color: #339933;">,</span> getNextKey<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'currentID'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #990000;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$form</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'0'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Bugs, preguntas, sugerencias, lo que sea es aceptado!.</p>
<p>Espero que les sirva!<br />
Saludos!!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cristianperez.com/2010/03/23/generador-de-id-continuas-al-estilo-url-corta/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Obtener el verdadero scope de un metodo en un objeto o clase PHP</title>
		<link>http://www.cristianperez.com/2010/02/19/obtener-el-verdadero-scope-de-un-metodo-en-un-objeto-o-clase-php/</link>
		<comments>http://www.cristianperez.com/2010/02/19/obtener-el-verdadero-scope-de-un-metodo-en-un-objeto-o-clase-php/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 20:47:50 +0000</pubDate>
		<dc:creator>Cristián</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.cristianperez.com/?p=259</guid>
		<description><![CDATA[La siguiente funcion soluciona el problema que tienen las funciones nativas de PHP para brindar informacion sobre metodos de Objetos o Clases.
La misma permite conocer si un metodo existe y a la vez, si es un metodo privado o publico.

Los valores que devuelve son:
0 Si el metodo no existe
1 Si el  [...]]]></description>
			<content:encoded><![CDATA[<p>La siguiente funcion soluciona el problema que tienen las funciones nativas de PHP para brindar informacion sobre metodos de Objetos o Clases.</p>
<p>La misma permite conocer si un metodo existe y a la vez, si es un metodo privado o publico.<br />
<span id="more-259"></span><br />
Los valores que devuelve son:<br />
0 Si el metodo no existe<br />
1 Si el metodo existe pero es privado<br />
2 Si el metodo existe y es publico</p>
<p>El codigo es el siguiente y espero que les sirva</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * @name Get Method Scope
 * @param mixed $class ClassName u Object
 * @param string $method
 * @return integer
 * 
 * @author Cristián Pérez
 * 
 * $class puede ser un objeto tambien
 * La funcion devuelve
 * 0: Si el metodo o la clase (u objeto) no existen
 * 1: Si el metodo existe pero es privado
 * 2: Si el metodo existe y es publico!
 * 
 **/</span>
<span style="color: #000000; font-weight: bold;">function</span> method_scope <span style="color: #009900;">&#40;</span><span style="color: #000088;">$class</span><span style="color: #339933;">,</span> <span style="color: #000088;">$method</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$all</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#41;</span><span style="color: #990000;">get_class_methods</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$class</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: #339933;">!</span> <span style="color: #990000;">in_array</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$method</span><span style="color: #339933;">,</span> <span style="color: #000088;">$all</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">method_exists</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$class</span><span style="color: #339933;">,</span> <span style="color: #000088;">$method</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Private</span>
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//It doesn't exists</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Public</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Ejemplo de Implementacion:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$scope</span> <span style="color: #339933;">=</span> method_scope <span style="color: #009900;">&#40;</span><span style="color: #000088;">$objeto</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;miMetodo&quot;</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;">$scope</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'El metodo es Publico'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Saludos</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cristianperez.com/2010/02/19/obtener-el-verdadero-scope-de-un-metodo-en-un-objeto-o-clase-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Borrar un directorio no vacio con PHP</title>
		<link>http://www.cristianperez.com/2010/01/05/borrar-un-directorio-no-vacio-con-php/</link>
		<comments>http://www.cristianperez.com/2010/01/05/borrar-un-directorio-no-vacio-con-php/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 21:31:54 +0000</pubDate>
		<dc:creator>Cristián</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[Recursos]]></category>

		<guid isPermaLink="false">http://www.cristianperez.com/?p=223</guid>
		<description><![CDATA[Muchos habran visto que al querer borrar un directorio que no esta vacio usando la funcion rmdir() nos arroja un error informandonos sobre esto
Por eso cree esta funcion que elimina todo el arbol completo de archivos y carpetas dentro de un directorio en particular

La definicion es la  [...]]]></description>
			<content:encoded><![CDATA[<p>Muchos habran visto que al querer borrar un directorio que no esta vacio usando la funcion rmdir() nos arroja un error informandonos sobre esto<br />
Por eso cree esta funcion que elimina todo el arbol completo de archivos y carpetas dentro de un directorio en particular<br />
<span id="more-223"></span></p>
<p>La definicion es la siguiente:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * Remove a non empty directory
 * @author Cristián Pérez
 * @param string $path Folder Path
 * @return bool
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> removeDirectory<span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$path</span> <span style="color: #339933;">=</span> <span style="color: #990000;">rtrim</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">strval</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$path</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'/'</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$d</span> <span style="color: #339933;">=</span> <span style="color: #990000;">dir</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$path</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: #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>
&nbsp;
    <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900; font-weight: bold;">false</span> <span style="color: #339933;">!==</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$current</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$d</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$current</span> <span style="color: #339933;">===</span> <span style="color: #0000ff;">'.'</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$current</span> <span style="color: #339933;">===</span> <span style="color: #0000ff;">'..'</span><span style="color: #009900;">&#41;</span>
            <span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$d</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">path</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$current</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">is_dir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
            removeDirectory<span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</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: #990000;">is_file</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
            <span style="color: #990000;">unlink</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #990000;">rmdir</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$d</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">path</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$d</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>La implementacion es la siguiente:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">removeDirectory<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/path/to/dir&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Espero que les sirva! Saludos!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cristianperez.com/2010/01/05/borrar-un-directorio-no-vacio-con-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Forzar descarga de un archivo</title>
		<link>http://www.cristianperez.com/2009/12/31/forzar-descarga-de-un-archivo/</link>
		<comments>http://www.cristianperez.com/2009/12/31/forzar-descarga-de-un-archivo/#comments</comments>
		<pubDate>Thu, 31 Dec 2009 18:15:24 +0000</pubDate>
		<dc:creator>Cristián</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[Recursos]]></category>

		<guid isPermaLink="false">http://www.cristianperez.com/?p=180</guid>
		<description><![CDATA[Muchas veces habran querido permitir la descarga de un archivo con extension &#8220;.php&#8221; por ejemplo de sus sitios sin tener que comprimirlo o un archivo de imagen, evitando que el navegador la muestre

La definicion de la funcion es la siguiente

function forceDownload&#40; $filePath &#41;
&#123;
    if&#40;  [...]]]></description>
			<content:encoded><![CDATA[<p>Muchas veces habran querido permitir la descarga de un archivo con extension &#8220;.php&#8221; por ejemplo de sus sitios sin tener que comprimirlo o un archivo de imagen, evitando que el navegador la muestre<br />
<span id="more-180"></span></p>
<p>La definicion de la funcion es la siguiente</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> forceDownload<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$filePath</span> <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">is_readable</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filePath</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-type: application/octet-stream&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Disposition: attachment; filename=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">$filePath</span><span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$fp</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filePath</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;r&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">fpassthru</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$fp</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">else</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Archivo no existente o sin permisos de lectura'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Y su utilizacion (por ejemplo) la siguiente</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">forceDownload<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/path/to/file.jpg&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Saludos!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cristianperez.com/2009/12/31/forzar-descarga-de-un-archivo/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Contar elementos repetidos en un array</title>
		<link>http://www.cristianperez.com/2009/12/31/contar-elementos-repetidos-en-un-array/</link>
		<comments>http://www.cristianperez.com/2009/12/31/contar-elementos-repetidos-en-un-array/#comments</comments>
		<pubDate>Thu, 31 Dec 2009 18:04:58 +0000</pubDate>
		<dc:creator>Cristián</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[Recursos]]></category>

		<guid isPermaLink="false">http://www.cristianperez.com/?p=178</guid>
		<description><![CDATA[Esta funcion devuelve un array con todos los elementos repetidos dentro de un array especifico, y la cantidad de veces que cada elemento aparecio

La definicion es la siguiente

function repeatedElements&#40;$array&#41;
&#160;
&#123;
    $repeated = array&#40;&#41;;
&#160;
&#160;
    foreach&#40; &#40;array&#41;$array as $value &#41;
    &#123;
         [...]]]></description>
			<content:encoded><![CDATA[<p>Esta funcion devuelve un array con todos los elementos repetidos dentro de un array especifico, y la cantidad de veces que cada elemento aparecio<br />
<span id="more-178"></span></p>
<p>La definicion es la siguiente</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> repeatedElements<span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span><span style="color: #009900;">&#41;</span>
&nbsp;
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$repeated</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
    <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#41;</span><span style="color: #000088;">$array</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$value</span> <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$inArray</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$repeated</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$rItem</span> <span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$rItem</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'value'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">===</span> <span style="color: #000088;">$value</span> <span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$inArray</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
                <span style="color: #339933;">++</span><span style="color: #000088;">$repeated</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'count'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #009900; font-weight: bold;">false</span> <span style="color: #339933;">===</span> <span style="color: #000088;">$inArray</span> <span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$repeated</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$repeated</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$repeated</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'value'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$repeated</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'count'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
    <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$repeated</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$rItem</span> <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rItem</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'count'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">===</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$repeated</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #990000;">sort</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$repeated</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$repeated</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Y la implementacion seria la siguiente por ejemplo</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$arrayParaChequear</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hola&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;chau&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;chau&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;hola&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$repetidos</span> <span style="color: #339933;">=</span> repeatedElements<span style="color: #009900;">&#40;</span><span style="color: #000088;">$arrayParaChequear</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$repetidos</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Y la salida del ejemplo anterior seria la siguiente</p>

<div class="wp_syntax"><div class="code"><pre class="plain" style="font-family:monospace;">Array
(
    [0] =&gt; Array
        (
            [value] =&gt; chau
            [count] =&gt; 2
        )
&nbsp;
    [1] =&gt; Array
        (
            [value] =&gt; hola
            [count] =&gt; 2
        )
&nbsp;
    [2] =&gt; Array
        (
            [value] =&gt; 1
            [count] =&gt; 2
        )
&nbsp;
)</pre></div></div>

<p>Como veran, es un array, cuyas claves son</p>
<p>&#8216;value&#8217;, que contiene el valor que se repitio<br />
&#8216;count&#8217; la cantidad de veces que aparecio</p>
<p>Espero que les sirva! <img src='http://www.cristianperez.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Saludos!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cristianperez.com/2009/12/31/contar-elementos-repetidos-en-un-array/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Open Komodo&#8230;.. Simplemente&#8230;.muy kómodo!</title>
		<link>http://www.cristianperez.com/2009/10/16/open-komodo-simplemente-muy-komodo/</link>
		<comments>http://www.cristianperez.com/2009/10/16/open-komodo-simplemente-muy-komodo/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 21:14:43 +0000</pubDate>
		<dc:creator>Cristián</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[GNU/Linux]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Programacion General]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://www.cristianperez.com/?p=157</guid>
		<description><![CDATA[Komodo IDE es, valga la redundancia, un IDE (Integrated Development Environment) orientado principalmente al desarrollo para la Web&#8230;
El proyecto esta liderado por la empresa Active State y su licencia paga.
Ahora bien, el proyecto Open Komodo inicia cuando Active State decide abrir parte  [...]]]></description>
			<content:encoded><![CDATA[<p><strong><img class="alignright size-full wp-image-158" title="komodo-logo" src="http://www.cristianperez.com/wp-content/uploads/2009/10/komodo.png" alt="komodo-logo" width="128" height="128" />Komodo IDE</strong> es, valga la redundancia, un IDE (Integrated Development Environment) orientado principalmente al desarrollo para la Web&#8230;<br />
El proyecto esta liderado por la empresa <a href="http://www.activestate.com/">Active State</a> y su licencia paga.<span id="more-157"></span></p>
<p>Ahora bien, el proyecto <strong>Open Komodo</strong> inicia cuando Active State decide abrir parte del código de Komodo IDE para crear <strong>Komodo Edit</strong>, el cual es un editor de código basado en el mencionado IDE.</p>
<p>Por si a alguno le quedan dudas Open Komodo no es el editor en si, sino que es el Repositorio del código fuente de Komodo Edit.</p>
<p>Ahora bien, mi experiencia con Komodo edit es 100% positiva!.</p>
<p>Algunas características que para mi son esenciales y que Komodo Edit cumple a la perfección son:</p>
<ul>
<li>Un buen coloreado del código</li>
<li>Inteligence, funcionando para mi gusto A LA PERFECCIÓN no solo en PHP, sino también para Javascript (Punto muy importante ya que no hay buenos editores de javascript y menos aun que cuenten con Inteligence ), HTML, XML, que son los que he testeado hasta el momento</li>
<li>Soporte para extensiones&#8230; Punto muy bueno!&#8230; Las mismas las pueden encontrar aca <a href="http://community.activestate.com/addons">http://community.activestate.com/addons</a></li>
</ul>
<p>Y muchos puntos mas que creo que no hace falta destacar porque no son mas que lo que se encuentra en el común denominador de los editores de código mas famosos.</p>
<p>Si vale recalcar la potencia de este editor, que cumple mis expectativas en un 100%, y que por cierto es también Multi-plataforma, lo cual no limita al usuario a usar este software bajo la plataforma que cada uno elija&#8230;</p>
<p>Recomiendo que lo prueben, y bueno, si a alguien le interesa o ya lo ha hecho, pueden probar también la versión Trial de Komodo IDE, la cual integra muchas ventajas mas, como debugger, syntax checking, HTML preview, entre muchisimas otras, y comentar que tal les ha ido!&#8230;</p>
<p>Para los que les interese les dejo la pagina del proyecto</p>
<p><a href="http://www.openkomodo.com/">http://www.openkomodo.com/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.cristianperez.com/2009/10/16/open-komodo-simplemente-muy-komodo/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Obtener datos de la transmision Shoutcast con PHP v2.0</title>
		<link>http://www.cristianperez.com/2009/09/14/obtener-datos-de-la-transmision-shoutcast-con-php/</link>
		<comments>http://www.cristianperez.com/2009/09/14/obtener-datos-de-la-transmision-shoutcast-con-php/#comments</comments>
		<pubDate>Mon, 14 Sep 2009 04:39:09 +0000</pubDate>
		<dc:creator>Cristián</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.cristianperez.com/?p=51</guid>
		<description><![CDATA[El contenido de este tema fue transladado aquí

Por favor no dejen mas comentarios en este post


]]></description>
			<content:encoded><![CDATA[<p><strong><span style="color: #ff0000;">El contenido de este tema fue transladado </span><a href="http://www.cristianperez.com/shoutcast-server-information/">aquí</a><br />
</strong></p>
<p><strong>Por favor no dejen mas comentarios en este post</strong></p>
<p><strong><br />
</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.cristianperez.com/2009/09/14/obtener-datos-de-la-transmision-shoutcast-con-php/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
	</channel>
</rss>

