<?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>Johan de Bruin &#187; PHP</title>
	<atom:link href="http://www.johandebruin.com/c/programacion/php-programacion/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.johandebruin.com</link>
	<description>Programación en php, tutorial de api wordpress y posicionamiento en buscadores seo.</description>
	<lastBuildDate>Sun, 05 Feb 2012 15:18:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Crear widget exportable a otras páginas web con el contenido de tu wordpress</title>
		<link>http://www.johandebruin.com/crear-widget-exportable-a-otras-paginas-web-con-el-contenido-de-tu-wordpress/</link>
		<comments>http://www.johandebruin.com/crear-widget-exportable-a-otras-paginas-web-con-el-contenido-de-tu-wordpress/#comments</comments>
		<pubDate>Sat, 17 Sep 2011 11:02:12 +0000</pubDate>
		<dc:creator>Johan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.johandebruin.com/?p=740</guid>
		<description><![CDATA[Para crear el widget hay 2 pasos fundamentales. Crear un canal RSS con el contenido que deseas exportar Crear el widget, puedes usar uno de las muchas aplicaciones online disponibles o simplemente programarlo Para el primer paso debemos especificar a wordpress que queremos crear un nuevo canal feed RSS, este canal aparecera con la siguiente [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.johandebruin.com/wp-content/uploads/2011/09/rss-icon-transparentpng.jpg" alt="RSS Widget WordPress" title="RSS Widget WordPress" width="150" height="150" class="aligncenter size-full wp-image-741" /><br />
Para crear el widget hay 2 pasos fundamentales.</p>
<ul>
<li>Crear un canal RSS con el contenido que deseas exportar
<li>Crear el widget, puedes usar uno de las muchas aplicaciones online disponibles o simplemente programarlo</li>
</ul>
<p>Para el primer paso debemos especificar a wordpress que queremos crear un nuevo canal feed RSS, este canal aparecera con la siguiente extrucutura URL:</p>
<p>http://www.ejemplo.com/?feed=ejemplo</p>
<p>http://www.ejemplo.com/feed/ejemplo/</p>
<p>Para ello creamos las siguientes funciones:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> mostrar_feed<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;hola mundo&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> incluir_feed<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	add_feed<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'publicadas'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'mostrar_feed'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'init'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'incluir_feed'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><span id="more-740"></span><br />
Esto podemos incluirlo como plugin o dentro del archivo functions.php de nuestro theme.</p>
<p>Ahora dentro de la funcion mostrar_feed() indicamos el contenido RSS que queremos crear, aqui un ejemplo del codigo que he usado para <a href="http://www.partidarios.com/?feed=publicadas" title="Publicadas partidarios">http://www.partidarios.com/?feed=publicadas</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> mostrar_feed<span style="color: #009900;">&#40;</span><span style="color: #000088;">$comment</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'
	&lt;rss version=&quot;2.0&quot;
	xmlns:content=&quot;http://purl.org/rss/1.0/modules/content/&quot;
	xmlns:wfw=&quot;http://wellformedweb.org/CommentAPI/&quot;
	xmlns:dc=&quot;http://purl.org/dc/elements/1.1/&quot;
	xmlns:atom=&quot;http://www.w3.org/2005/Atom&quot;
	xmlns:sy=&quot;http://purl.org/rss/1.0/modules/syndication/&quot;
	xmlns:slash=&quot;http://purl.org/rss/1.0/modules/slash/&quot;
	&gt;
&nbsp;
&lt;channel&gt;
	&lt;title&gt;Partidarios&lt;/title&gt;
	&lt;atom:link href=&quot;http://www.partidarios.com/?feed=publicadas&quot; rel=&quot;self&quot; type=&quot;application/rss+xml&quot; /&gt;
	&lt;link&gt;http://www.partidarios.com&lt;/link&gt;
	&lt;description&gt;Feed con las ultimas publicadas de los partidos politicos.&lt;/description&gt;
	&lt;lastBuildDate&gt;Sat, 17 Sep 2011 09:45:25 +0000&lt;/lastBuildDate&gt;
&nbsp;
	&lt;language&gt;es&lt;/language&gt;
	&lt;sy:updatePeriod&gt;hourly&lt;/sy:updatePeriod&gt;
	&lt;sy:updateFrequency&gt;1&lt;/sy:updateFrequency&gt;
	&lt;generator&gt;http://wordpress.org/?v=3.2.1&lt;/generator&gt;'</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$the_query</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> WP_Query<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'cat'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">27</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'meta_key'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'publicada'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'meta_value'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'1'</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$the_query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">have_posts</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$the_query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">the_post</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$id_partido2</span> <span style="color: #339933;">=</span> get_post_custom_values<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id_partido'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$id_partido</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$id_partido2</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>				
					<span style="color: #000088;">$facebook</span> <span style="color: #339933;">=</span> get_post_custom_values<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'facebook'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$id_partido</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$partido</span> <span style="color: #339933;">=</span> get_the_title<span style="color: #009900;">&#40;</span><span style="color: #000088;">$id_partido</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$mensaje</span> <span style="color: #339933;">=</span> get_the_title<span style="color: #009900;">&#40;</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: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$mensaje</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">245</span><span style="color: #009900;">&#41;</span>
					<span style="color: #009900;">&#123;</span>
						<span style="color: #000088;">$mensaje</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$mensaje</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">245</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'...'</span><span style="color: #339933;">;</span>
					<span style="color: #009900;">&#125;</span>
					<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&lt;item&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
					<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;title&gt;<span style="color: #006699; font-weight: bold;">$partido</span>: <span style="color: #006699; font-weight: bold;">$mensaje</span>&lt;/title&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
					<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;link&gt;&quot;</span><span style="color: #339933;">.</span>get_permalink<span style="color: #009900;">&#40;</span>get_the_ID<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/link&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
					<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;comments&gt;&quot;</span><span style="color: #339933;">.</span>get_permalink<span style="color: #009900;">&#40;</span>get_the_ID<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;#comments&lt;/comments&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
					<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;pubDate&gt;&quot;</span><span style="color: #339933;">.</span>get_the_date<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'D, d M Y H:i:s O'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/pubDate&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
					<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;		&lt;dc:creator&gt;admin&lt;/dc:creator&gt;<span style="color: #000099; font-weight: bold;">\n</span>
						&lt;category&gt;&lt;![CDATA[Mensaje]]&gt;&lt;/category&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
					<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;guid isPermaLink=&quot;false&quot;&gt;'</span><span style="color: #339933;">.</span>get_permalink<span style="color: #009900;">&#40;</span>get_the_ID<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/guid&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
					<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;description&gt;&lt;![CDATA[]]&gt;&lt;/description&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
					<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;content:encoded&gt;&lt;![CDATA[]]&gt;&lt;/content:encoded&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
					<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/item&gt;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;
	&lt;/channel&gt;
&lt;/rss&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Por ultimo podemos emplear una de las muchas aplicaciones online que genera widgets a partir de archivos RSS. Una de las más sencillas es <a href="http://www.widgeteasy.com" title="Widget Facil" target="_blank">http://www.widgeteasy.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.johandebruin.com/crear-widget-exportable-a-otras-paginas-web-con-el-contenido-de-tu-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Clase de php Http Bot con CURL</title>
		<link>http://www.johandebruin.com/clase-de-php-http-bot-con-curl/</link>
		<comments>http://www.johandebruin.com/clase-de-php-http-bot-con-curl/#comments</comments>
		<pubDate>Sun, 05 Jun 2011 19:35:07 +0000</pubDate>
		<dc:creator>Johan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programacion]]></category>
		<category><![CDATA[bot]]></category>
		<category><![CDATA[Clase]]></category>
		<category><![CDATA[clase php]]></category>
		<category><![CDATA[Clases php]]></category>
		<category><![CDATA[CURL]]></category>
		<category><![CDATA[HTTP bot]]></category>
		<category><![CDATA[http bot php]]></category>

		<guid isPermaLink="false">http://www.johandebruin.com/?p=696</guid>
		<description><![CDATA[Esta clase de php sirve para enviar solicitudes a un servidor a través de un protocolo HTTP usando la tecnologia CURL, ya sea para obtener el codigo HTML de la página usando el metodo GET, o postear algo a través del método POST. Recordad que podeis obtener la cookie usando programas de SNIFER tales como [...]]]></description>
			<content:encoded><![CDATA[<p>Esta clase de php sirve para enviar solicitudes a un servidor a través de un protocolo HTTP usando la tecnologia <a href="http://es.wikipedia.org/wiki/CURL">CURL</a>, ya sea para obtener el codigo HTML de la página usando el metodo GET, o postear algo a través del método POST.</p>
<p>Recordad que podeis obtener la cookie usando programas de SNIFER tales como el plugin para firefox <a href="https://addons.mozilla.org/es-es/firefox/addon/tamper-data/">tamper data</a>, gracias a esta libreria se puede configurar el alta automatica de nuevas entradas de post en clasificados, lista de enlaces, etc&#8230;</p>
<p>La forma en la que se usa esta clase 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;">&lt;?</span>
	<span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;curlbot.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$bot</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> curlbot<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$bot</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">galleta</span> <span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;b.txt&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$mensaje</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;_method=POST&amp;data%5BUser%5D%5Bname%5D=usuario&amp;data%5BUser%5D%5Bpassword%5D=contrasena&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$bot</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://www.mister-wong.es/users/login/&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$mensaje</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$bot</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://www.mister-wong.es/&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;fin&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p><span id="more-696"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>
<span style="color: #000000; font-weight: bold;">class</span> curlbot
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$encabezado</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: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$galleta</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//Cambiar a false en caso de que no se quiera redireccionar</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$redireccionar</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//Definimos como deben establecerse los atributos</span>
	<span style="color: #000000; font-weight: bold;">function</span> __set<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</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: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;galleta&quot;</span><span style="color: #009900;">&#41;</span>
			<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;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
				<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">else</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'w'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">galleta</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;encabezado&quot;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">encabezado</span><span style="color: #009900;">&#91;</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: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">redireccionar</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//Envia una solicitud get y devuelve la pagina obtenida</span>
		<span style="color: #666666; font-style: italic;">///Param{$url}: url de la pagina que queramos obtener</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> get<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</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: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">encabezado</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
			<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #339933;">,</span> CURLOPT_HTTPHEADER<span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">encabezado</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;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">galleta</span> <span style="color: #339933;">!=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #339933;">,</span> CURLOPT_COOKIEJAR<span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">galleta</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #339933;">,</span> CURLOPT_COOKIEFILE<span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">galleta</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		<span style="color: #009900;">&#125;</span>
		<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #339933;">,</span> CURLOPT_FOLLOWLOCATION<span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">redireccionar</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">//Enviamos la petición</span>
		<span style="color: #000088;">$respuesta</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$respuesta</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//Envia una solicitud post y devuelve la pagina obtenida</span>
		<span style="color: #666666; font-style: italic;">//Param{$url}: dirección de la pagina que solicitamos el post</span>
		<span style="color: #666666; font-style: italic;">//Param{$campos}: mensaje del post que queramos enviar, ejemplo:</span>
			<span style="color: #666666; font-style: italic;">//&quot;user=usuario&amp;pass=contraseña&quot;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> post<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span><span style="color: #000088;">$campos</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</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: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">encabezado</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
			<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #339933;">,</span> CURLOPT_HTTPHEADER<span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">encabezado</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;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">galleta</span> <span style="color: #339933;">!=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #339933;">,</span> CURLOPT_COOKIEJAR<span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">galleta</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #339933;">,</span> CURLOPT_COOKIEFILE<span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">galleta</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		<span style="color: #009900;">&#125;</span>
		<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #339933;">,</span> CURLOPT_POST<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #339933;">,</span> CURLOPT_POSTFIELDS<span style="color: #339933;">,</span> <span style="color: #000088;">$campos</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #339933;">,</span> CURLOPT_FOLLOWLOCATION<span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">redireccionar</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">//Enviamos la petición</span>
		<span style="color: #000088;">$respuesta</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$respuesta</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?</span>php<span style="color: #339933;">&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.johandebruin.com/clase-de-php-http-bot-con-curl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>API Facebook Graph con PHP, funciones basicas</title>
		<link>http://www.johandebruin.com/api-facebook-graph-con-php-funciones-basicas/</link>
		<comments>http://www.johandebruin.com/api-facebook-graph-con-php-funciones-basicas/#comments</comments>
		<pubDate>Wed, 15 Dec 2010 15:50:28 +0000</pubDate>
		<dc:creator>Johan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programacion]]></category>
		<category><![CDATA[api facebook]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[facebook open graph]]></category>
		<category><![CDATA[php facebook]]></category>

		<guid isPermaLink="false">http://www.johandebruin.com/?p=642</guid>
		<description><![CDATA[Bueno, tras un mesecillo sin publicar nada quiero consolidar el conocimiento con el que últimamente he trabajado, por lo que relataré en este artículo como usar la nueva API de Facebook Graph para poder programar aplicaciones empleandola. Para descargar la última versión de la libreria de PHP de facebook podeis visitar el sdk de php [...]]]></description>
			<content:encoded><![CDATA[<p>Bueno, tras un mesecillo sin publicar nada quiero consolidar el conocimiento con el que últimamente he trabajado, por lo que relataré en este artículo como usar la nueva API de Facebook Graph para poder programar aplicaciones empleandola.</p>
<p>Para descargar la última versión de la libreria de PHP de facebook podeis visitar el <a title="facebook sdk api php" href="http://github.com/facebook/php-sdk/">sdk de php de facebook</a>.</p>
<p>La nueva tecnologia de facebook permite tanto consultar como desarrollar distintas aplicaciones usando unicamente la funcion $facebook->api(parametros). Discutiremos una serie de cosas de entre ellas será:</p>
<ol>
<li>Crear el archivo de configuración de API facebook</li>
<li>Autentificar al usuario solicitandole los permisos necesarios</li>
<li>Solicitar información a facebook usando FQL</li>
<li>Actualizar el estado de facebook o publicar en el muro de uno de sus amigos</li>
</ol>
<p><span id="more-642"></span><br />
Archivo config.php</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'APP_ID'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'id aplicacion'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'API_KEY'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Key API'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SECRET'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Key Secreta de la aplicacion'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$facebook</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Facebook<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
  <span style="color: #0000ff;">'appId'</span>  <span style="color: #339933;">=&gt;</span> API_KEY<span style="color: #339933;">,</span>
  <span style="color: #0000ff;">'secret'</span> <span style="color: #339933;">=&gt;</span> SECRET<span style="color: #339933;">,</span>
  <span style="color: #0000ff;">'cookie'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span>
<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Ahora que el objeto $facebook se ha creado, comprobaremos si se ha iniciado la sesión, en caso contrario la redirigiremos a una página donde el usuario concederá los permisos necesarios para obtener información de su perfil, publicar en su estado, enviarle e-mails, etc&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$sesion</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getSession</span><span style="color: #009900;">&#40;</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;">$sesion</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$loginUrl</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLoginUrl</span><span style="color: #009900;">&#40;</span>
		<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'canvas'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'fbconnect'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'req_perms'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'publish_stream,read_stream,user_photo_video_tags,user_photos,friends_photos'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'next'</span>      <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'http://urlsiconsienten.com'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'cancel_url'</span><span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'http://facebook.com/'</span>
&nbsp;
		<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;fb:redirect url=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$loginUrl</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; /&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>A menudo necesitaremos el ID de la persona autentificada, esto se consigue de la siguiente forma:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$fbusuario</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUser</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Si quisieramos solicitar información sobre un usuario concreto, podemos emplear el lenguaje <a href="http://developers.facebook.com/docs/reference/fql/">FQL </a>(de facebook query language), junto con el graph api de facebook de php.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$fql</span>    <span style="color: #339933;">=</span>   <span style="color: #0000ff;">&quot;select name, hometown_location, sex, pic_square from user where uid=&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$fbusuario</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$param</span>  <span style="color: #339933;">=</span>   <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
                <span style="color: #0000ff;">'method'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'fql.query'</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'query'</span>     <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$fql</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'callback'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span>
            <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$fqlResult</span>   <span style="color: #339933;">=</span>   <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">api</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$param</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Esto nos devolverá una matriz con los datos correlacionados, otras acciones que podemos realizar con la api de facebook es publicar un estado en nuestro propio muro o en el muro de otra persona/página en la que estemos autorizados a hacerlo (gracias a los permisos).</p>
<p>Para ello podemos emplear el siguiente código:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//Este se publicara en el muro del usuario autentificado</span>
<span style="color: #000088;">$statusUpdate</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">api</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/me/feed'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'post'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'message'</span><span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'H.O.L.A M.U.N.D.O'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'cb'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//Este se publicará en el id del usuario</span>
<span style="color: #000088;">$statusUpdate</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">api</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/1304862638/feed'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'post'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'message'</span><span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'H.O.L.A M.U.N.D.O'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'cb'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>También se puede emplear el metodo anterior (llamado legacy), para solicitar otro tipo de información, como las peliculas del perfil de usuario, más información en el <a href=http://developers.facebook.com/docs/api">graph API de facebook</a> o también información de cada <a href="http://developers.facebook.com/docs/reference/api/">elemento de la api de facebook</a></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$movies</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">api</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/me/movies'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.johandebruin.com/api-facebook-graph-con-php-funciones-basicas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>2 dominios, 2 idiomas, htaccess, wordpress, alias y 1 servidor</title>
		<link>http://www.johandebruin.com/2-dominios-2-idiomas-htaccess-wordpress-alias-y-1-servidor/</link>
		<comments>http://www.johandebruin.com/2-dominios-2-idiomas-htaccess-wordpress-alias-y-1-servidor/#comments</comments>
		<pubDate>Thu, 09 Sep 2010 11:15:44 +0000</pubDate>
		<dc:creator>Johan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programacion]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.johandebruin.com/?p=615</guid>
		<description><![CDATA[Hoy voy a hablaros de una de las tecnicas mas enrevesadas para conseguir que tengamos 2 idiomas en un mismo servidor pero usando 2 dominios distintos (y asi reforzar el posicionamiento seo por dominios del pais). La forma en la que os lo muestro es usando wordpress, pero por supuesto se podria adaptar para otros [...]]]></description>
			<content:encoded><![CDATA[<p>Hoy voy a hablaros de una de las tecnicas mas enrevesadas para conseguir que tengamos 2 idiomas en un mismo servidor pero usando 2 dominios distintos (y asi reforzar el posicionamiento seo por dominios del pais).</p>
<p>La forma en la que os lo muestro es usando wordpress, pero por supuesto se podria adaptar para otros cms o vuestros propios sistemas. Primero deciros que usaremos el plugin de traducción de idiomas estilo <a href="http://wordpress.org/extend/plugins/zdmultilang/">zdMultilang</a> que nos permitira crear subdirectorios estilo dominioprincipal.es/en/ para las traducciones.</p>
<p>Una vez hecho esto, debeis añadir un <a href="http://www.seocharlie.com/blog/los-alias-de-dominio-y-el-posicionamiento-seo">alias </a>al dominio principal para que al entrar desde el segundo dominio conecte con las dns del servidor principal.</p>
<p>Ahora comenzamos a tocar las lineas de codigo, primero abriremos el htaccess y añadiremos las siguientes instrucciones para que el dominio secundario haga un proxy al dominio principal y obtenga la url actual pero añadiendo /en/ al host. En este ejemplo el dominio principal es un .es y el dominio secundario (en ingles o internacional) es el .com:</p>

<div class="wp_syntax"><div class="code"><pre class="robots" style="font-family:monospace;">RewriteEngine on
RewriteCond %<span style="color: #66cc66;">&#123;</span>HTTP_HOST<span style="color: #66cc66;">&#125;</span> ^<span style="color: #66cc66;">&#40;</span>www\.<span style="color: #66cc66;">&#41;</span>?dominiosecundario\.com <span style="color: #66cc66;">&#91;</span>NC<span style="color: #66cc66;">&#93;</span>
RewriteRule ^<span style="color: #66cc66;">&#40;</span>.*<span style="color: #66cc66;">&#41;</span>$ http<span style="color: #66cc66;">:</span>//www.dominioprincipal.es/en/$1 <span style="color: #66cc66;">&#91;</span>P<span style="color: #66cc66;">&#93;</span>
&nbsp;
RewriteRule ^/?<span style="color: #66cc66;">&#40;</span>en<span style="color: #66cc66;">&#41;</span>/wp-<span style="color: #66cc66;">&#40;</span>.*<span style="color: #66cc66;">&#41;</span>$ /wp-$2 <span style="color: #66cc66;">&#91;</span>L<span style="color: #66cc66;">&#93;</span></pre></div></div>

<p><span id="more-615"></span><br />
Además, añadirmos la instrucción RewriteRule ^/?(en)/wp-(.*)$ /wp-$2 [L] para que todos las peticiones que comiencen con wp- ignoren el /en/. Esto se hace para que en la versión inglesa pueda obtener el contenido de imagenes, o scripts de forma correcta..</p>
<p>Ahora incluiremos algunas líneas de código de wordpress, que haran que detecten si se está en el dominio secundario y cambie las url de las imagenes y los scripts a este dominio con tal de evitar incompatibilidades de rutas, etc.. Estas lineas se pueden incluir en el archivo functions.php del theme o en forma de plugin, esto se pone a vuestra discreción&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'bloginfo'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'mybloginfo'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'bloginfo_url'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'mybloginfo'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> mybloginfo<span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #339933;">=</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$show</span><span style="color: #339933;">=</span><span style="color: #0000ff;">''</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;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'/en/'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</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: #b1b100;">return</span> <span style="color: #990000;">ereg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'dominioprincipal.es'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'dominiosecundario.com'</span><span style="color: #339933;">,</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$result</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Bien, ya tenemos hecho la base necesaria para poder incluir un segundo idioma en el servidor con 2 dominios distintos, podemos usar la instrucción if (strpos($_SERVER['REQUEST_URI'],&#8217;/en/&#8217;) > -1) para detectar si estamos en la versión inglesa de la traducción y cambiar valores del contenido, como menus, o rutas&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.johandebruin.com/2-dominios-2-idiomas-htaccess-wordpress-alias-y-1-servidor/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Configurar el loop de wordpress</title>
		<link>http://www.johandebruin.com/configurar-el-loop-de-wordpress/</link>
		<comments>http://www.johandebruin.com/configurar-el-loop-de-wordpress/#comments</comments>
		<pubDate>Wed, 30 Jun 2010 11:26:26 +0000</pubDate>
		<dc:creator>Johan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[API wordpress]]></category>
		<category><![CDATA[Custom loop]]></category>

		<guid isPermaLink="false">http://www.johandebruin.com/?p=609</guid>
		<description><![CDATA[Hoy os traigo otro artículo para incorporarlo en la api de wordpress, el loop de wordpress es invocado cada vez que solicitamos articulos o páginas, en el index por ejemplo sale por defecto la solicitud de los últimos artículos publicados, en el archivo los articulos de cierto mes o cierta categoria, etc&#8230; La api de [...]]]></description>
			<content:encoded><![CDATA[<p>Hoy os traigo otro artículo para incorporarlo en la <a href="http://www.johandebruin.com/tutorial-api-wordpress/">api de wordpress</a>, el <strong>loop de wordpress </strong>es invocado cada vez que solicitamos articulos o páginas, en el index por ejemplo sale por defecto la solicitud de los últimos artículos publicados, en el archivo los articulos de cierto mes o cierta categoria, etc&#8230;</p>
<p>La <strong>api de wordpress nos permite una configuración bastante intensa </strong>de la forma de solicitar y mostrar contenido en los loops de wordpress, lo primero de todo es establecer los posts que queramos mostrar en el loop, se puede hacer usando la función <a href="http://codex.wordpress.org/Function_Reference/query_posts">query_posts()</a>;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">query_posts<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'cat=4,5'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Todos los que esten en la categoria 4 y 5</span>
query_posts<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tag=mitag'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Los que tengan cierto tag...</span>
query_posts<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'meta_key=nombrekey&amp;amp;meta_value=valorkey'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Tenga un campo personalizado con dichos valores</span>
&nbsp;
 <span style="color: #000088;">$categoria</span><span style="color: #339933;">=</span><span style="color: #000088;">$cat</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// asignamos la actual categoria</span>
 <span style="color: #000088;">$query</span><span style="color: #339933;">=</span> <span style="color: #0000ff;">'cat='</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$categoria</span><span style="color: #339933;">.</span> <span style="color: #0000ff;">'&amp;amp;orderby=date&amp;amp;order=ASC'</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//ordenacion ascendente por fecha</span>
 query_posts<span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><span id="more-609"></span><br />
Como veis, tenemos mucho con que jugar a la hora de configurar el contenido del loop de wordpress, una vez hecho podemos crear el loop, tiene la siguiente estructura:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> the_post<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//...</span>
<span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">else</span><span style="color: #339933;">:</span>
<span style="color: #666666; font-style: italic;">//...</span>
<span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span>
wp_reset_query<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Importante reiniciar loop para que wordpress funcione como habitualmente</span></pre></div></div>

<p>Una vez dentro del loop podemos llamar a muchos valores de los posts, como por ejemplo el contenido, los tags, fecha, titulos, extracto, campos personalizados, la categoria&#8230; Aquí un ejemplo de como seria el código completo</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">query_posts('cat='.get_cat_ID('miCategoria')); //Establecemos el query con los posts de &quot;miCategoria&quot;
if (have_posts()) : while (have_posts()) : the_post();
     &lt;p&gt;&lt;h1&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/h1&gt;&lt;/p&gt;
     &lt;p&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_excerpt<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> ?<span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span>
     <span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php the_content<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/p&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$postMeta</span> <span style="color: #339933;">=</span> get_post_custom_values<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'metaKey'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$postMeta</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;p&gt;<span style="color: #006699; font-weight: bold;">$key</span>  =&gt; <span style="color: #006699; font-weight: bold;">$value</span> ('metaKey')&lt;/p&gt;&quot;</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
endwhile; else:
    echo &quot;No se encontraron articulos relacionados, puede que le interese alguna de las siguientes categorias&quot;
&lt;ul&gt;
   <span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_list_categories<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/ul&gt;
endif;
wp_reset_query();</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.johandebruin.com/configurar-el-loop-de-wordpress/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Crear Plantillas de themes para post en WordPress</title>
		<link>http://www.johandebruin.com/crear-plantillas-de-themes-para-post-en-wordpress/</link>
		<comments>http://www.johandebruin.com/crear-plantillas-de-themes-para-post-en-wordpress/#comments</comments>
		<pubDate>Thu, 17 Jun 2010 20:42:28 +0000</pubDate>
		<dc:creator>Johan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[Custom Values]]></category>
		<category><![CDATA[Plantilla]]></category>
		<category><![CDATA[Post meta]]></category>
		<category><![CDATA[Theme]]></category>
		<category><![CDATA[Wordpress API]]></category>

		<guid isPermaLink="false">http://www.johandebruin.com/?p=599</guid>
		<description><![CDATA[Podemos crear una plantilla para publicar post especificos en wordpress de la misfa forma que ocurre con las páginas gracias a la combinación del uso de la API de wordpress y del plugin Custom Post Template. Lo que queremos conseguir es mostrar posts de distintas maneras en función a que plantilla seleccionamos en el menu [...]]]></description>
			<content:encoded><![CDATA[<p>Podemos crear una plantilla para publicar post especificos en wordpress de la misfa forma que ocurre con las páginas gracias a la combinación del uso de la API de wordpress y del plugin <a title="Plantilla Post WordPress" href="http://wordpress.org/extend/plugins/custom-post-template/">Custom Post Template</a>. Lo que queremos conseguir es mostrar posts de distintas maneras en función a que plantilla seleccionamos en el menu de post:</p>
<p><a href="http://www.johandebruin.com/wp-content/uploads/2010/06/post-template.jpg"><img src="http://www.johandebruin.com/wp-content/uploads/2010/06/post-template.jpg" alt="" title="post template" width="296" height="365" class="aligncenter size-full wp-image-600" /></a></p>
<p>Gracias a eso, y a un formato de recognición de templates de post, con que añadamos el siguiente comentario en el .php del theme de wordpress podremos definir un formato especifico para ese tipo de post (como añadir metas especificos, imagenes, colores, opciones etc&#8230; especifico), explotando más las posibilidades de wordpress.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">/*
Template Name Posts: nombrePlantilla
*/</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p><span id="more-599"></span><br />
Aqui un ejemplo de como podriamos adaptar esta plantilla usando comandos de la API de wordpress (lo tipico, llamada al header, titulos, contenido, campos personalizados.. ).</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">/*
Template Name Posts: nombrePlantilla
*/</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> get_header<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'home'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> the_post<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
   &lt;h1&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/h1&gt;
   <span style="color: #000000; font-weight: bold;">&lt;?php</span> the_content<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&lt;p class=&quot;serif&quot;&gt;Leer el resto del post;&lt;/p&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
   $postMeta = get_post_custom_values('metaKey');
   foreach ( $postMeta as $key =&gt; $value ) {
      echo &quot;$key  =&gt; $value ('metaKey')&lt;br /&gt;&quot;; 
   }
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.johandebruin.com/crear-plantillas-de-themes-para-post-en-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Programacion orientada a objetos y diagramas UML en PHP</title>
		<link>http://www.johandebruin.com/programacion-orientada-a-objetos-y-diagramas-uml-en-php/</link>
		<comments>http://www.johandebruin.com/programacion-orientada-a-objetos-y-diagramas-uml-en-php/#comments</comments>
		<pubDate>Tue, 11 May 2010 06:10:48 +0000</pubDate>
		<dc:creator>Johan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[clases]]></category>
		<category><![CDATA[php5]]></category>
		<category><![CDATA[poo]]></category>
		<category><![CDATA[programacion orientada a objetos]]></category>
		<category><![CDATA[uml]]></category>
		<category><![CDATA[uml php]]></category>

		<guid isPermaLink="false">http://www.johandebruin.com/?p=525</guid>
		<description><![CDATA[Una recopilación de como construir clases en PHP junto a un diagrama de la relación UML. Útil para ir obteniendo nociones sobre el modelado del código. Herencia Indica que una clase hereda todos los atributos y métodos de otra, hay que tener en cuenta que en el diagrama UML el triangulo toca al padre: class [...]]]></description>
			<content:encoded><![CDATA[<p>Una recopilación de como construir clases en PHP junto a un diagrama de la relación UML. Útil para ir obteniendo nociones sobre el modelado del código.</p>
<h3>Herencia</h3>
<p>Indica que una clase hereda todos los atributos y métodos de otra, hay que tener en cuenta que en el diagrama UML el triangulo toca al padre:</p>
<pre lang="php" style="float:left;width:420px">
class Senior {

}
class Junior extends Senior {

}
</pre>
<p><img style="float:right" src="http://www.johandebruin.com/wp-content/uploads/2010/05/herencia.gif" alt="herencia php" title="herencia php" width="102" height="179" class="aligncenter size-full wp-image-527" /><br />
<br style="clear: both" /><br />
<span id="more-525"></span></p>
<h3>Agregación</h3>
<p>Es cuando una clase puede es parte de otra, con lo cual esta primera clase tendrá acceso a los métodos de la segunda. Al haber sido instanciada fuera de la segunda, aunque esta muera la primera seguira viviendo. Se les conoce como clases &#8220;Data Access&#8221;, y se dice que la primera clase controla parte de la segunda. Se relacionan con un diamante que toca la clase controlada</p>
<pre lang="php" style="float:left;width:420px">
class Dao {
    function getSomething() {
    }
}
class Model {
    var $dao;
    function Model (&#038; $dao) {
        $this->dao=&#038; $dao;
    }
    function doSomething () {
        $this->dao->getSomething();
    }
}
$dao=new Dao;
$model=new Model($dao);
$model->doSomething();
</pre>
<p><img style="float:right" src="http://www.johandebruin.com/wp-content/uploads/2010/05/agregacionpoo.gif" alt="herencia php" title="herencia php" width="102" height="179" class="aligncenter size-full wp-image-527" /></p>
<p><br style="clear: both" /></p>
<h3>Composición</h3>
<p>Es cuando una clase instancia a otra, esta segunda instancia moriria con la primera, esto significa que la primera clase controla a toda la segunda, se representa con un solido diamante tocando a la clase controlada.</p>
<pre lang="php" style="float:left;width:420px">
class LinkWidget {
}
class View {
    var $linkWidget;
    var $page;
    function View () {
        $this->linkWidget=new LinkWidget;
    }
    function renderPage () {
        $this->page=$this->linkWidget->display()
    }
}
</pre>
<p><img style="float:right" src="http://www.johandebruin.com/wp-content/uploads/2010/05/composicionpooo.gif" alt="herencia php" title="herencia php" width="102" height="179" class="aligncenter size-full wp-image-527" /></p>
<p><br style="clear: both" /></p>
<h3>Mensajes</h3>
<p>Es cuando una clase comunica a otra que está controlando una instancia suya. En php suele emplearse el <a href="http://www.php.net/manual/en/keyword.paamayim-nekudotayim.php">operador scope</a>. Que sirve para hacer referencias a métodos de clases que no estan instanciadas.</p>
<pre lang="php" style="float:left;width:420px">
class HtmlUtils {
    function unHtmlEntities ($str) {
        $trans_tbl =
get_html_translation_table (HTML_ENTITIES);
        $trans_tbl = array_flip ($trans_tbl);
        return strtr ($str, $trans_tbl);
    }
}
class View {
    function renderPage {
        $text=HtmlUtils::unHtmlEntities($text);
    }
}
</pre>
<p><img style="float:right" src="http://www.johandebruin.com/wp-content/uploads/2010/05/mensajeUnidireccionalpoo.gif" alt="herencia php" title="herencia php" width="102" height="179" class="aligncenter size-full wp-image-527" /></p>
<p><br style="clear: both" /><br />
Existe otra variante de esta relación, donde el mensaje se envia mutuamente entre las dos clases, un ejemplo de código:</p>
<pre lang="php" style="float:left;width:420px">
class Debug {
    function display () {
        echo ($this->errorMsg);
    }
}
class SomeClass {
    var $errorMsg='This is an error message';
    function someFunction () {
        if ( DEBUG == 1 ) {
            Debug::display();
        }
    }
}
define ('DEBUG',1);
$someClass= &#038;new SomeClass;
$someClass->someFunction();
</pre>
<p><img style="float:right" src="http://www.johandebruin.com/wp-content/uploads/2010/05/bidireccionalpoo.gif" alt="bidireccional php" title="herencia php" width="102" height="179" class="aligncenter size-full wp-image-527" /></p>
<p><br style="clear: both" /></p>
<p>Fuente, <a href="http://www.phppatterns.com/docs/design/php_and_uml_class_diagrams">phppatterns</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.johandebruin.com/programacion-orientada-a-objetos-y-diagramas-uml-en-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Subir un archivo usando ftp con php</title>
		<link>http://www.johandebruin.com/subir-un-archivo-usando-ftp-con-php/</link>
		<comments>http://www.johandebruin.com/subir-un-archivo-usando-ftp-con-php/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 20:22:30 +0000</pubDate>
		<dc:creator>Johan de Bruin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Archivo]]></category>
		<category><![CDATA[ftp]]></category>

		<guid isPermaLink="false">http://www.johandebruin.com/?p=433</guid>
		<description><![CDATA[Bueno, rebuscando entre mis códigos olvidados he encontrado este pequeño snnipet que puede salvarte la vida en más de una ocasión. Usar el ftp con php puede ser muy sencillo gracias a esta función, sus parametros son: $dir: ftp del servidor. $user: usuario del ftp $pass: contraseña $desde: ruta donde se localiza el archivo que [...]]]></description>
			<content:encoded><![CDATA[<p>Bueno, rebuscando entre mis códigos olvidados he encontrado este pequeño snnipet que puede salvarte la vida en más de una ocasión. Usar el ftp con php puede ser muy sencillo gracias a esta función, sus parametros son:</p>
<ul>
<li>$dir: ftp del servidor.</li>
<li>$user: usuario del ftp</li>
<li>$pass: contraseña</li>
<li>$desde: ruta donde se localiza el archivo que se desea subir</li>
<li>$hacia: ruta donde quieres alojar el archivo</li>
</ul>
<p><span id="more-433"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> subirFTP<span style="color: #009900;">&#40;</span><span style="color: #000088;">$dir</span><span style="color: #339933;">,</span><span style="color: #000088;">$user</span><span style="color: #339933;">,</span><span style="color: #000088;">$pass</span><span style="color: #339933;">,</span><span style="color: #000088;">$desde</span><span style="color: #339933;">,</span><span style="color: #000088;">$hacia</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	try
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$idConn</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ftp_connect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dir</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">ftp_login</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$idConn</span><span style="color: #339933;">,</span><span style="color: #000088;">$user</span><span style="color: #339933;">,</span><span style="color: #000088;">$pass</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">ftp_put</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$idConn</span><span style="color: #339933;">,</span><span style="color: #000088;">$hacia</span><span style="color: #339933;">,</span><span style="color: #000088;">$desde</span><span style="color: #339933;">,</span>FTP_BINARY<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">ftp_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$idConn</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	catch<span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$e</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</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: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.johandebruin.com/subir-un-archivo-usando-ftp-con-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Clase de conexión a Bases datos php</title>
		<link>http://www.johandebruin.com/clase-de-conexion-a-bases-datos-php/</link>
		<comments>http://www.johandebruin.com/clase-de-conexion-a-bases-datos-php/#comments</comments>
		<pubDate>Sat, 02 Jan 2010 23:38:16 +0000</pubDate>
		<dc:creator>Johan de Bruin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Bases datos]]></category>
		<category><![CDATA[Clases php]]></category>
		<category><![CDATA[Programacion]]></category>

		<guid isPermaLink="false">http://www.johandebruin.com/?p=176</guid>
		<description><![CDATA[Con esta clase de php, te facilitará la tarea de conectarte a las bases de datos, resumiendo en unas pocas líneas de código la interconexión con la base de datos en mysql. La forma de uso es la siguiente: //Parametros del constructor: host, user, pass, tabla $bd = new datos&#40;&#34;localhost&#34;,&#34;root&#34;,&#34;&#34;,&#34;bd&#34;&#41;; //la función obtener uno extrae [...]]]></description>
			<content:encoded><![CDATA[<p>Con esta <strong>clase de php</strong>, te facilitará la tarea de conectarte a las <strong>bases de datos</strong>, resumiendo en unas pocas líneas de código la interconexión con la base de datos en mysql. La forma de uso es la siguiente:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//Parametros del constructor: host, user, pass, tabla</span>
<span style="color: #000088;">$bd</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> datos<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;localhost&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;root&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;bd&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//la función obtener uno extrae un string directamente con el primer resultado</span>
<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$bd</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">obtenerUno</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT MAX(columna) FROM tabla&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//La función obtener devuelve una matriz de mysql</span>
<span style="color: #000088;">$matriz</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$bd</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">obtener</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT columna FROM tabla&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fila</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$matriz</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
     <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;br /&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$fila</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'columna'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//La función insertar es para insertar o editar columnas, devuelve el numero de filas afectadas</span>
<span style="color: #000088;">$filasAfectadas</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$bd</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">insertar</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;INSERT INTO tabla VALUES ('a','b')&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><span id="more-176"></span><br />
La clase de php en cuestión 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;">&lt;?</span>
<span style="color: #000000; font-weight: bold;">class</span> datos
<span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">/* Clase de conexion a bases de datos con php
Creado por johandebruin.com en 02-01-2010 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$server</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$user</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$pass</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$bd</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//Funcion generica que devuelve una conexion a la BD</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> conectar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$idConexion</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">server</span><span style="color: #339933;">,</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user</span><span style="color: #339933;">,</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">pass</span><span style="color: #009900;">&#41;</span>
			or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;No fue posible conectar con la base de datos, intentelo mÃ¡s tarde&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bd</span><span style="color: #339933;">,</span><span style="color: #000088;">$idConexion</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #339933;">@</span><span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SET NAMES 'utf8'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$idConexion</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//Establecemos los parametros</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$servidor</span><span style="color: #339933;">,</span><span style="color: #000088;">$usuario</span><span style="color: #339933;">,</span><span style="color: #000088;">$contra</span><span style="color: #339933;">,</span><span style="color: #000088;">$baseDatos</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">server</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$servidor</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$usuario</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">pass</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$contra</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bd</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$baseDatos</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//Obtenemos una matriz de datos, false si no existen</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> obtener<span style="color: #009900;">&#40;</span><span style="color: #000088;">$consulta</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$idConexion</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">conectar</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$datos</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$consulta</span><span style="color: #339933;">,</span><span style="color: #000088;">$idConexion</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">mysql_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$idConexion</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;">mysql_num_rows</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$datos</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">1</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: #b1b100;">return</span> <span style="color: #000088;">$datos</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//Obtenemos un solo resultado, o en su mayorecto el primero, false en su defecto</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> obtenerUno<span style="color: #009900;">&#40;</span><span style="color: #000088;">$consulta</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$idConexion</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">conectar</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$datos</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$consulta</span><span style="color: #339933;">,</span><span style="color: #000088;">$idConexion</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">mysql_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$idConexion</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;">mysql_num_rows</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$datos</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">1</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: #b1b100;">return</span> <span style="color: #990000;">mysql_result</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$datos</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//Devuelve el numero de filas afectadas</span>
	<span style="color: #000000; font-weight: bold;">function</span> insertar<span style="color: #009900;">&#40;</span><span style="color: #000088;">$consulta</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$idConexion</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">conectar</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$respuesta</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$consulta</span><span style="color: #339933;">,</span><span style="color: #000088;">$idConexion</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: #990000;">mysql_affected_rows</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$idConexion</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">mysql_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$idConexion</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$i</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.johandebruin.com/clase-de-conexion-a-bases-datos-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Funcion extraer subcadena php</title>
		<link>http://www.johandebruin.com/funcion-extraer-subcadena-php/</link>
		<comments>http://www.johandebruin.com/funcion-extraer-subcadena-php/#comments</comments>
		<pubDate>Tue, 29 Dec 2009 10:47:02 +0000</pubDate>
		<dc:creator>Johan de Bruin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[cadena]]></category>
		<category><![CDATA[Programacion]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[subcadena]]></category>

		<guid isPermaLink="false">http://www.johandebruin.com/?p=167</guid>
		<description><![CDATA[Esta función de PHP la cree hace tiempo, su finalidad es la de extraer una subcadena de una cadena o string en PHP. Además, puedes indicar la itineración para que no extraiga la primera subcadena que encuentre. Es extremadamente útil a la hora de manejar strings en HTML. Los parámetros son los siguientes: $cadena: la [...]]]></description>
			<content:encoded><![CDATA[<p>Esta función de PHP la cree hace tiempo, su finalidad es la de extraer una <strong>subcadena </strong>de una cadena o string en PHP. Además, puedes indicar la itineración para que no extraiga la primera <strong>subcadena </strong>que encuentre. Es extremadamente útil a la hora de manejar strings en <strong>HTML</strong>. Los parámetros son los siguientes:</p>
<ul>
<li>$<strong>cadena</strong>: la cadena que se va a evaluar</li>
<li>$<strong>antes</strong>: lo que aparece antes de la subcadena que se quiere extraer</li>
<li>$<strong>despues</strong>: lo que aparece después de la subcadena que se quiere extraer</li>
<li>$<strong>cuenta</strong>: el número de veces que se tiene que repetir la coincidencia hasta devolver la subcadena</li>
</ul>
<p>Ejemplo:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$cadena</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Esto es una lista..&lt;ul&gt;&lt;li&gt;Hola mundo&lt;/li&gt; &lt;li&gt;Hola mundo2&lt;/li&gt;&lt;/ul&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Primera subcadena: &quot;</span> <span style="color: #339933;">.</span>extraer<span style="color: #009900;">&#40;</span><span style="color: #000088;">$cadena</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&lt;li&gt;&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&lt;/li&gt;&quot;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;br /&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Segunda subcadena: &quot;</span> <span style="color: #339933;">.</span>extraer<span style="color: #009900;">&#40;</span><span style="color: #000088;">$cadena</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&lt;li&gt;&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&lt;/li&gt;&quot;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><span id="more-167"></span><br />
Y aquí esta la función deseada:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> extraer<span style="color: #009900;">&#40;</span><span style="color: #000088;">$cadena</span><span style="color: #339933;">,</span><span style="color: #000088;">$antes</span><span style="color: #339933;">,</span><span style="color: #000088;">$despues</span><span style="color: #339933;">,</span><span style="color: #000088;">$cuenta</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">/*Función para obtener extraer una subcadena
	Creado por johandebruin.com el 29-12-2009*/</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$cuenta</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;">//Ponemos en minuscula todo para optimizar el algoritmo;</span>
	<span style="color: #000088;">$cadena</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cadena</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$antes</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$antes</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$despues</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$despues</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$localizacion1</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$localizacion2</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">do</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$localizacion1</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cadena</span><span style="color: #339933;">,</span><span style="color: #000088;">$antes</span><span style="color: #339933;">,</span><span style="color: #000088;">$localizacion1</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</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;">$localizacion1</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">false</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: #000088;">$cuenta</span><span style="color: #339933;">--;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$cuenta</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$localizacion2</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cadena</span><span style="color: #339933;">,</span> <span style="color: #000088;">$despues</span><span style="color: #339933;">,</span> <span style="color: #000088;">$localizacion1</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</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;">$localizacion2</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">false</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: #000088;">$localizacion1</span> <span style="color: #339933;">+=</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$antes</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cadena</span><span style="color: #339933;">,</span><span style="color: #000088;">$localizacion1</span><span style="color: #339933;">,</span><span style="color: #000088;">$localizacion2</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$localizacion1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.johandebruin.com/funcion-extraer-subcadena-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

