<?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>Bufa Webmaster &#187; Funciones</title>
	<atom:link href="http://www.bufa.es/web/php/funciones-php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bufa.es</link>
	<description>Recursos web en español</description>
	<lastBuildDate>Wed, 01 Sep 2010 20:50:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>PHP: Convertir fecha MySQL a fecha Unix</title>
		<link>http://www.bufa.es/convertir-fecha-mysql-unix/</link>
		<comments>http://www.bufa.es/convertir-fecha-mysql-unix/#comments</comments>
		<pubDate>Wed, 01 Sep 2010 20:50:50 +0000</pubDate>
		<dc:creator>bufa</dc:creator>
				<category><![CDATA[Funciones]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[fecha]]></category>
		<category><![CDATA[strtotime]]></category>

		<guid isPermaLink="false">http://www.bufa.es/?p=509</guid>
		<description><![CDATA[Si tenemos una determinada fecha de nuestra base de datos mysql con el formato DATE (000-00-00) año-mes-dia, y la queremos convertir en formato unix (en un string) lo podemos hacer con esta simple función que utiliza basicamente la función strtotime, ...]]></description>
			<content:encoded><![CDATA[<p>Si tenemos una determinada fecha de nuestra base de datos mysql con el formato DATE (000-00-00) año-mes-dia, y la queremos convertir en formato unix (en un string) lo podemos hacer con esta simple función que utiliza basicamente la función <strong>strtotime</strong>, que lo que hace es convertir una cadena que contenga un formato de fecha en Inglés US a una fecha Unix.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> fecha_mysql_to_unix<span style="color: #009900;">&#40;</span><span style="color: #000088;">$fecha</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$phpdate</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fecha</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$phpdate</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
Modo de uso<span style="color: #339933;">:</span>
<span style="color: #000088;">$fecha</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'2010-06-10'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> echa_mysql_to_unix<span style="color: #009900;">&#40;</span><span style="color: #000088;">$fecha</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// imprimiría: 1276120800</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.bufa.es/convertir-fecha-mysql-unix/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Función php: convertir direcciones url en enlaces</title>
		<link>http://www.bufa.es/convertir-url-enlaces/</link>
		<comments>http://www.bufa.es/convertir-url-enlaces/#comments</comments>
		<pubDate>Fri, 02 Jul 2010 16:49:56 +0000</pubDate>
		<dc:creator>bufa</dc:creator>
				<category><![CDATA[Funciones]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[expresiones irregulares]]></category>
		<category><![CDATA[preg_replace]]></category>

		<guid isPermaLink="false">http://www.bufa.es/?p=462</guid>
		<description><![CDATA[Una función muy sencilla que nos será de utilidad cuando queramos convertir automaticamente todas las direcciones url (que comiencen por http) en hiperenlaces. Para ello utilizamos expresiones irregulares junto con la función preg_replace de php. $cadena = &#34;Este es un ...]]></description>
			<content:encoded><![CDATA[<p>Una función muy sencilla que nos será de utilidad cuando queramos convertir automaticamente todas las direcciones url (que comiencen por http) en hiperenlaces. Para ello utilizamos expresiones irregulares junto con la función <strong>preg_replace</strong> de php.</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;Este es un texto que contiene una dirección url http://www.leonpurpura.com&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> convertirUrls<span style="color: #009900;">&#40;</span><span style="color: #000088;">$cadena</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#http://([A-z0-9./-]+)#&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;a href=&quot;$1&quot;&gt;$0&lt;/a&gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$cadena</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;">// Modo de uso:</span>
<span style="color: #b1b100;">echo</span> convertirUrls<span style="color: #009900;">&#40;</span><span style="color: #000088;">$cadena</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.bufa.es/convertir-url-enlaces/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Obtener cadena resultante entre 2 palabras</title>
		<link>http://www.bufa.es/obtener-cadena-entre-2-palabras/</link>
		<comments>http://www.bufa.es/obtener-cadena-entre-2-palabras/#comments</comments>
		<pubDate>Fri, 02 Jul 2010 16:35:43 +0000</pubDate>
		<dc:creator>bufa</dc:creator>
				<category><![CDATA[Funciones]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[explode]]></category>

		<guid isPermaLink="false">http://www.bufa.es/?p=460</guid>
		<description><![CDATA[Vamos a crear una función en php para obtener la cadena de texto comprendida entre otras 2 palabras o cadenas de texto (inicio, fín). Utilizaremos la función explode para dividir en 2 partes la cadena y obtener así la cadena ...]]></description>
			<content:encoded><![CDATA[<p>Vamos a crear una función en php para obtener la cadena de texto comprendida entre otras 2 palabras o cadenas de texto (inicio, fín). Utilizaremos la función <strong>explode</strong> para dividir en 2 partes la cadena y obtener así la cadena resultante comprendida entre esas 2 otras variables.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> obtenerCadena<span style="color: #009900;">&#40;</span><span style="color: #000088;">$contenido</span><span style="color: #339933;">,</span><span style="color: #000088;">$incio</span><span style="color: #339933;">,</span><span style="color: #000088;">$fin</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$r</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$inicio</span><span style="color: #339933;">,</span> <span style="color: #000088;">$contenido</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;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$r</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$r</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fin</span><span style="color: #339933;">,</span> <span style="color: #000088;">$r</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$r</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: #009900;">&#125;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Modo de uso</span>
<span style="color: #000088;">$mitexto</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Sin León no hubiera España, que antes que Castilla leyes, Concilios, fueros y reyes, dieron prestigio a León. La fama cantó su hazaña con clarines de victoria: ¡León escribió la historia de Covadonga a Colón! Con su sangre a torrentes vertida dio a la Patria preciado blasón y en sus labios cobró vida el hermoso lenguaje español'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> obtenerCadena<span style="color: #009900;">&#40;</span><span style="color: #000088;">$mitexto</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'fama'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'victoria'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Resultado: cantó su hazaña con clarines de</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.bufa.es/obtener-cadena-entre-2-palabras/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Comprimir código fuente html con PHP</title>
		<link>http://www.bufa.es/comprimir-codigo-html-php/</link>
		<comments>http://www.bufa.es/comprimir-codigo-html-php/#comments</comments>
		<pubDate>Sun, 16 May 2010 16:29:17 +0000</pubDate>
		<dc:creator>bufa</dc:creator>
				<category><![CDATA[Funciones]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[comprimir]]></category>
		<category><![CDATA[expresiones irregulares]]></category>
		<category><![CDATA[ob_end_flush]]></category>
		<category><![CDATA[ob_start]]></category>

		<guid isPermaLink="false">http://www.bufa.es/?p=378</guid>
		<description><![CDATA[Vamos a ver una función en php muy interesante si queremos reducir el peso de nuestras páginas web, eliminando espacios en blanco innecesarios en nuestro código html final. Quedándonos nuestro código fuente final limpio de espacios en blanco innecesarios, tabulaciones, ...]]></description>
			<content:encoded><![CDATA[<p>Vamos a ver una función en php muy interesante si queremos reducir el peso de nuestras páginas web, eliminando espacios en blanco innecesarios en nuestro código html final. Quedándonos nuestro código fuente final limpio de espacios en blanco innecesarios, tabulaciones, etc&#8230;</p>
<p>En la función se utilizan expresiones irregulares, pero debemos tener cuidado con ella ya que consumen bastantes recursos en el servidor, pero si las utilizamos por ejemplo para para subir el contenido bienen muy bien.</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;">//habilitamos el uso de búferes de salida</span>
<span style="color: #990000;">ob_start</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'comprimir_pagina'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Mi web&lt;/title&gt;
&lt;/head&gt;
&nbsp;
&lt;body&gt;
&nbsp;
    &lt;div&gt;
        Realizamos un par de tabulaciones
    &lt;/div&gt;
&nbsp;
&lt;/body&gt;
&lt;/html&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// Una vez que el búfer almacena nuestro contenido utilizamos &quot;ob_end_flush&quot; para usarlo y deshabilitar el búfer</span>
<span style="color: #990000;">ob_end_flush</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #666666; font-style: italic;">// Función para eliminar todos los espacios en blanco</span>
<span style="color: #000000; font-weight: bold;">function</span> comprimir_pagina<span style="color: #009900;">&#40;</span><span style="color: #000088;">$buffer</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
	<span style="color: #000088;">$busca</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/\&gt;[^\S ]+/s'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'/[^\S ]+\&lt;/s'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'/(\s)+/s'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #000088;">$reemplaza</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&gt;'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'&lt;'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'\\1'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #b1b100;">return</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$busca</span><span style="color: #339933;">,</span> <span style="color: #000088;">$reemplaza</span><span style="color: #339933;">,</span> <span style="color: #000088;">$buffer</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span> 
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Resultado del código fuente final:</p>

<div class="wp_syntax"><div class="code"><pre class="xhtml" style="font-family:monospace;">&lt;html&gt;&lt;head&gt;&lt;title&gt;Mi web&lt;/title&gt;&lt;/head&gt;&lt;body&gt; &lt;div&gt; Realizamos un par de tabulaciones &lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.bufa.es/comprimir-codigo-html-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Función para limitar caracteres en los post de WordPress</title>
		<link>http://www.bufa.es/funcion-limitar-caracteres-post-wordpress/</link>
		<comments>http://www.bufa.es/funcion-limitar-caracteres-post-wordpress/#comments</comments>
		<pubDate>Sat, 01 May 2010 16:51:07 +0000</pubDate>
		<dc:creator>bufa</dc:creator>
				<category><![CDATA[Funciones]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[caracteres]]></category>
		<category><![CDATA[función]]></category>

		<guid isPermaLink="false">http://www.bufa.es/?p=311</guid>
		<description><![CDATA[Función muy completa para cuando queremos personalizar un poco el listado de post del archive.php o index.php de nuestro wordpress, y que debemos incluir en nuestro functions.php. Con ella podemos personalizar el número de caracteres por post, así como el ...]]></description>
			<content:encoded><![CDATA[<p>Función muy completa para cuando queremos personalizar un poco el listado de post  del archive.php o index.php de nuestro wordpress, y que debemos incluir en nuestro <strong>functions.php</strong>. Con ella podemos personalizar el número de caracteres por post, así como el texto del link (&#8216;Leer mas&#8230;, Read more, Seguir, etc&#8230;&#8217;)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> wp_limit_post<span style="color: #009900;">&#40;</span><span style="color: #000088;">$max_char</span><span style="color: #339933;">,</span> <span style="color: #000088;">$more_link_text</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'[...]'</span><span style="color: #339933;">,</span><span style="color: #000088;">$notagp</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #000088;">$stripteaser</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$more_file</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: #000088;">$content</span> <span style="color: #339933;">=</span> get_the_content<span style="color: #009900;">&#40;</span><span style="color: #000088;">$more_link_text</span><span style="color: #339933;">,</span> <span style="color: #000088;">$stripteaser</span><span style="color: #339933;">,</span> <span style="color: #000088;">$more_file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> apply_filters<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'the_content'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">']]&gt;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">']]&amp;gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strip_tags</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'p'</span><span style="color: #009900;">&#93;</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: #009900;">&#123;</span>
      <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$notagp</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">echo</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #000088;">$max_char</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;p&gt;'</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">echo</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #000088;">$max_char</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/p&gt;&quot;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span>
   <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&gt;</span><span style="color: #000088;">$max_char</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$espacio</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$max_char</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$espacio</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$content</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$notagp</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #000088;">$max_char</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$more_link_text</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;p&gt;'</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #000088;">$max_char</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$more_link_text</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/p&gt;&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span>
   <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$notagp</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">echo</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #000088;">$max_char</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;p&gt;'</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">echo</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #000088;">$max_char</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/p&gt;&quot;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Modo de uso:</span>
wp_limit_post<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">180</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'...'</span><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></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.bufa.es/funcion-limitar-caracteres-post-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Averiguar la extensión de un archivo con php</title>
		<link>http://www.bufa.es/averiguar-extension-archivo/</link>
		<comments>http://www.bufa.es/averiguar-extension-archivo/#comments</comments>
		<pubDate>Sat, 24 Apr 2010 22:56:12 +0000</pubDate>
		<dc:creator>bufa</dc:creator>
				<category><![CDATA[Funciones]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[extensión]]></category>

		<guid isPermaLink="false">http://www.bufa.es/?p=299</guid>
		<description><![CDATA[Averiguar la extensión de un archivo con php es una tarea muy sencilla utilizando la función explode. Veámos un ejemplo que podemos utilizar a la hora de validar formularios. Vamos a crear una función para usarla más a menudo. 1 ...]]></description>
			<content:encoded><![CDATA[<p>Averiguar la extensión de un archivo con php es una tarea muy sencilla utilizando la función explode. Veámos un ejemplo que podemos utilizar a la hora de validar formularios. Vamos a crear una función para usarla más a menudo.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> extension<span style="color: #009900;">&#40;</span><span style="color: #000088;">$archivo</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> 
   <span style="color: #000088;">$partes</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$archivo</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
   <span style="color: #000088;">$extension</span> <span style="color: #339933;">=</span> <span style="color: #990000;">end</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$partes</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
   <span style="color: #b1b100;">return</span> <span style="color: #000088;">$extension</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Modo de uso</span>
extension<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;thenumberofthebeast.mp3&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.bufa.es/averiguar-extension-archivo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Insertar imágen miniatura en cada post de WordPress</title>
		<link>http://www.bufa.es/insertar-miniatura-post-wordpress/</link>
		<comments>http://www.bufa.es/insertar-miniatura-post-wordpress/#comments</comments>
		<pubDate>Fri, 02 Apr 2010 13:24:43 +0000</pubDate>
		<dc:creator>bufa</dc:creator>
				<category><![CDATA[Funciones]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[miniatura]]></category>

		<guid isPermaLink="false">http://www.bufa.es/?p=273</guid>
		<description><![CDATA[Al habilitar esta funcionalidad en nuestros temas de wordpress tendremos la posibilidad de añadir una imágen miniatura independiente desde el administrador de wordpress. Todo lo que necesitamos es añadir una o dos líneas al fichero functions.php de nuestra carpeta del ...]]></description>
			<content:encoded><![CDATA[<p>Al habilitar esta funcionalidad en nuestros temas de wordpress tendremos la posibilidad de añadir una imágen miniatura independiente desde el administrador de wordpress. Todo lo que necesitamos es añadir una o dos líneas al fichero functions.php de nuestra carpeta del theme.</p>
<p>Insertamos las siguientes líneas al archivo <em>functions.php</em>:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">add_theme_support<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'post-thumbnails'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// añadimos la función para crear una nueva caja en el administrador para insertar la foto</span>
set_post_thumbnail_size <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">200</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">200</span><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: #666666; font-style: italic;">// redimensionamos la miniatura al tamaño deseado</span></pre></td></tr></table></div>

<p>Una vez editado este archivo entramos en el administrador de wordpress, insertamos o editamos un post y veremos que aparece una nueva caja en el lateral derecho llamada &#8220;Miniatura de entrada&#8221;.</p>
<p>Para hacer uso de la miniatura en nuestros post añadimos el siguiente código al loop en el lugar exacto donde queremos que aparezca:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">the_post_thumbnail<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.bufa.es/insertar-miniatura-post-wordpress/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Cadena de texto en varias columnas</title>
		<link>http://www.bufa.es/cadena-texto-varias-columnas/</link>
		<comments>http://www.bufa.es/cadena-texto-varias-columnas/#comments</comments>
		<pubDate>Sun, 07 Feb 2010 16:26:38 +0000</pubDate>
		<dc:creator>bufa</dc:creator>
				<category><![CDATA[Funciones]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[cadenas]]></category>
		<category><![CDATA[columnas]]></category>

		<guid isPermaLink="false">http://www.bufa.es/?p=258</guid>
		<description><![CDATA[Hace poco, he tenido que utilizar esta función para poder dividir en 2 columnas una determinada cadena de texto. Con la siguiente función php podemos también pasarle como parámetro el número de columnas que queremos. Para representar las columnas utilizaremos ...]]></description>
			<content:encoded><![CDATA[<p>Hace poco, he tenido que utilizar esta función para poder <strong>dividir en 2 columnas</strong> una determinada cadena de texto. Con la siguiente función php podemos también pasarle como parámetro el número de columnas que queremos.</p>
<p>Para representar las columnas utilizaremos css y una lista ul que será la que generemos de la cadena original.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$cadena</span> <span style="color: #339933;">=</span><span style="color: #0000ff;">'Sin León no hubiera España, que antes que Castilla leyes, Concilios, fueros y reyes, dieron prestigio a León. La fama cantó su hazaña con clarines de victoria: ¡León escribió la historia de Covadonga a Colón! Con su sangre a torrentes vertida dio a la Patria preciado blasón y en sus labios cobró vida el hermoso lenguaje español ¡Viva León! Tierra hidalga, tierra mía: estrofas del romancero, desde Guzmán a don Suero, va tremolando el honor. Con su sangre a torrentes vertida dio a la Patria preciado blasón y en sus labios cobró vida el hermoso lenguaje español. De piedra una plegaria la catedral semeja, sobria y gentil refleja el alma de León. De historia milenaria, de santidad osario, del arte relicario y de la fe expresión. Tierra hidalga, tierra mía: estrofas del romancero, desde Guzmán a don Suero, va tremolando el honor. Con su sangre a torrentes vertida dio a la Patria preciado blasón y en sus labios cobró vida el hermoso lenguaje español. Gloria a ti, pueblo sin par; a mi labio el corazón se asoma para gritar: ¡Viva León! ¡Viva León!'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> cadena_columnas <span style="color: #009900;">&#40;</span><span style="color: #000088;">$cadena</span><span style="color: #339933;">,</span> <span style="color: #000088;">$columnas</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$salida</span> <span style="color: #339933;">=</span>  <span style="color: #0000ff;">'&lt;ul class=&quot;columnas&quot;&gt;'</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$cuerpotexto</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$cadena</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// generamos una matriz de la cadena</span>
  <span style="color: #000088;">$texto</span> <span style="color: #339933;">=</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;,&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$cuerpotexto</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// obtenemos cadena que contiene una representación de todos los elementos de la matriz en el mismo orden</span>
  <span style="color: #000088;">$longitud</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$texto</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// determinamos la longitud de la cadena</span>
  <span style="color: #000088;">$longitud</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ceil</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$longitud</span><span style="color: #339933;">/</span><span style="color: #000088;">$columnas</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// redondeamos la longitud hacia arriba devolviendo el entero más cercano dividiendola entre el nº de columnas</span>
  <span style="color: #000088;">$palabras</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$texto</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// buscamos las palabras sueltas separadas por espacios</span>
  <span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$palabras</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// contamos el número de palabras</span>
  <span style="color: #000088;">$l</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #339933;">&lt;=</span><span style="color: #000088;">$columnas</span><span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$nuevacadena</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$salida</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;li&gt;'</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$g</span><span style="color: #339933;">=</span><span style="color: #000088;">$l</span><span style="color: #339933;">;</span><span style="color: #000088;">$g</span><span style="color: #339933;">&lt;=</span><span style="color: #000088;">$c</span><span style="color: #339933;">;</span><span style="color: #000088;">$g</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$nuevacadena</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;=</span> <span style="color: #000088;">$longitud</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$columnas</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000088;">$nuevacadena</span><span style="color: #339933;">.=</span><span style="color: #000088;">$palabras</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$g</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$l</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$g</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
     <span style="color: #009900;">&#125;</span>
    <span style="color: #000088;">$salida</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$nuevacadena</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$salida</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;/li&gt;'</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000088;">$salida</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;/ul&gt;'</span><span style="color: #339933;">;</span> 
  <span style="color: #b1b100;">return</span> <span style="color: #000088;">$salida</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">// Modo de empleo: (por ejemplo para dividir el texto en 3 li o columnas)</span>
<span style="color: #b1b100;">echo</span> cadena_columnas<span style="color: #009900;">&#40;</span><span style="color: #000088;">$cadena</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Por último ya solo falta darle un estilo en nuestro archivo css de estilos:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="css" style="font-family:monospace;">.columnas<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">list-style</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">font-family</span><span style="color: #3333ff;">:Arial</span><span style="color: #00AA00;">,</span> Helvetica<span style="color: #00AA00;">,</span> <span style="color: #993333;">sans-serif</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">12px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">333</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.columnas</span> li<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;"><span style="color: #cc66cc;">25</span>%</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span>  <span style="color: #933;">20px</span> <span style="color: #933;">20px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">15px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#ccc</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.bufa.es/cadena-texto-varias-columnas/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Función php contar número de palabras de una cadena</title>
		<link>http://www.bufa.es/funcion-php-contar-palabras/</link>
		<comments>http://www.bufa.es/funcion-php-contar-palabras/#comments</comments>
		<pubDate>Sun, 07 Feb 2010 11:25:29 +0000</pubDate>
		<dc:creator>bufa</dc:creator>
				<category><![CDATA[Funciones]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[cadenas]]></category>
		<category><![CDATA[contar]]></category>

		<guid isPermaLink="false">http://www.bufa.es/?p=238</guid>
		<description><![CDATA[Función php para contar el número de palabras de una determinada cadena. Podemos usarla para limitar a un determinado número de palabras en alguna sección de nuestra web, etc. 1 2 3 4 5 6 7 function contar_palabras&#40;$cadena&#41;&#123; return sizeof&#40;explode&#40;&#34; ...]]></description>
			<content:encoded><![CDATA[<p>Función php para contar el número de <strong>palabras de una determinada cadena</strong>. Podemos usarla para limitar a un determinado número de palabras en alguna sección de nuestra web, etc.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> contar_palabras<span style="color: #009900;">&#40;</span><span style="color: #000088;">$cadena</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #990000;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$cadena</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">// Modo de empleo:</span>
<span style="color: #000088;">$cadena</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;¡¡¡Sin LEÓN no hubiera España, que antes que Castilla leyes, Concilios, fueros y reyes, dieron prestigio a León!!!&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> contar_palabras<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: #666666; font-style: italic;">// Resultado: 18</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.bufa.es/funcion-php-contar-palabras/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Función php validar url de dominio</title>
		<link>http://www.bufa.es/funcion-validar-url/</link>
		<comments>http://www.bufa.es/funcion-validar-url/#comments</comments>
		<pubDate>Sun, 07 Feb 2010 00:34:28 +0000</pubDate>
		<dc:creator>bufa</dc:creator>
				<category><![CDATA[Funciones]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[función]]></category>
		<category><![CDATA[urls]]></category>
		<category><![CDATA[validar]]></category>

		<guid isPermaLink="false">http://www.bufa.es/?p=228</guid>
		<description><![CDATA[Función en php utilizando una expresión regular para validar cualquier tipo de url de dominio. 1 2 3 4 5 6 7 8 9 10 $url = &#34;http://www.bufa.es&#34;; function valida_url&#40;$url&#41;&#123; if &#40;preg_match&#40;'/^(http&#124;https&#124;ftp):\/\/([\w]*)\.([\w]*)\.(com&#124;net&#124;org&#124;biz&#124;info&#124;mobi&#124;us&#124;cc&#124;bz&#124;tv&#124;ws&#124;name&#124;co&#124;me)(\.[a-z]{1,3})?\z/i', $url&#41;&#41; &#123; echo 'dominio correcto'; &#125;else&#123; echo 'dominio ...]]></description>
			<content:encoded><![CDATA[<p>Función en php utilizando una expresión regular para validar cualquier tipo de url de dominio.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://www.bufa.es&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">function</span> valida_url<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: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/^(http|https|ftp):\/\/([\w]*)\.([\w]*)\.(com|net|org|biz|info|mobi|us|cc|bz|tv|ws|name|co|me)(\.[a-z]{1,3})?\z/i'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$url</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;">'dominio correcto'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>  
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'dominio incorrecto'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">// Modo de uso</span>
valida_url<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.bufa.es/funcion-validar-url/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
