<?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>Webserveis</title>
	<atom:link href="http://www.webserveis.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.webserveis.com</link>
	<description>Blog de desarrollo web</description>
	<lastBuildDate>Wed, 15 Feb 2012 18:55:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Clase para crear newsletter</title>
		<link>http://www.webserveis.com/195/clase-para-crear-newsletter/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=clase-para-crear-newsletter</link>
		<comments>http://www.webserveis.com/195/clase-para-crear-newsletter/#comments</comments>
		<pubDate>Tue, 07 Feb 2012 17:34:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[PHP Snippets]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.webserveis.com/?p=195</guid>
		<description><![CDATA[&#60;?php /* * @class simplenewsletter * @author webserveis * @web www.webserveis.com * @email webserveis@gmail.com * @copyright webserveis * @date 07/02/2012 * @license GPL * @usage &#160; $NewsLetter = new SimpleNewsLetter('localhost','user','password','database'); $NewsLetter-&#62;createtable('Newsletter'); echo ''; if ($NewsLetter-&#62;addemail('prova@hotmail.com')) echo 'Insert'; else echo 'alredy exist'; echo ''; if ($NewsLetter-&#62;delEmail('prova@hotmail.com')) echo 'email eliminado'; else echo 'no se ha encotrado email'; [...]]]></description>
			<content:encoded><![CDATA[
<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;">/*
* @class simplenewsletter
* @author webserveis
* @web www.webserveis.com
* @email webserveis@gmail.com
* @copyright webserveis
* @date 07/02/2012
* @license GPL
* @usage
&nbsp;
$NewsLetter = new SimpleNewsLetter('localhost','user','password','database');
$NewsLetter-&gt;createtable('Newsletter');
echo '';
if ($NewsLetter-&gt;addemail('prova@hotmail.com')) echo 'Insert'; else echo 'alredy exist';
echo '';
if ($NewsLetter-&gt;delEmail('prova@hotmail.com')) echo 'email eliminado'; else echo 'no se ha encotrado email';
if ($NewsLetter-&gt;addemail('prova@hotmail.com')) echo 'Insert'; else echo 'alredy exist';
if ($NewsLetter-&gt;addemail('prova@hotmail.com')) echo 'Insert'; else echo 'alredy exist';
if ($NewsLetter-&gt;addemail('prova2@hotmail.com')) echo 'Insert'; else echo 'alredy exist';
echo ''.$NewsLetter-&gt;listemails();
&nbsp;
*/</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> SimpleNewsLetter <span style="color: #009900;">&#123;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$DB_Link</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
   <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$DB</span><span style="color: #339933;">;</span>
   <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$Table</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</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: #000088;">$host</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;">$dbname</span><span style="color: #339933;">,</span><span style="color: #000088;">$table</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'Newsletter'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #666666; font-style: italic;">/*
   * @call $var = new SimpleNewsLetter(@params);
   * @param string host: host del mysql server
   * @param string user: nom d'usuari del mysql server
   * @param string dbname: nom de la base de dades
   * @param string table: nom de la taula per ingresar els emails, per defecte 'newsletter'
   */</span>
      <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">DB_Link</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$host</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: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">DB</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dbname</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">DB_Link</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;">Table</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$table</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> __destruct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #990000;">mysql_close</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">DB_Link</span> <span style="color: #009900;">&#41;</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> createtable<span style="color: #009900;">&#40;</span><span style="color: #000088;">$table</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'Newsletter'</span><span style="color: #339933;">,</span><span style="color: #000088;">$delete</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #666666; font-style: italic;">/*
   * @call $var-&gt;createtable(@params);
   * @param string table: nom de la taula, per defecte 'Newsletter'
   * @param bool delete: si es 'true' eliminara la taula existent, per defecte esta a 'false'
   */</span>
      <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Table</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$table</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$Sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$delete</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         <span style="color: #000088;">$Sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'DROP TABLE IF EXISTS `'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Table</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'`;'</span><span style="color: #339933;">;</span>
         <span style="color: #000088;">$Result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$Sql</span><span style="color: #339933;">,</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">DB_Link</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #000088;">$Sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'CREATE TABLE IF NOT EXISTS `'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Table</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'` (`Id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,`Email` VARCHAR( 256 ) NOT NULL ,UNIQUE (`Email`)) ENGINE = MYISAM CHARACTER SET utf8'</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$Result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$Sql</span><span style="color: #339933;">,</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">DB_Link</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">return</span> <span style="color: #000088;">$Result</span><span style="color: #339933;">;</span>
&nbsp;
   <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> listemails<span style="color: #009900;">&#40;</span><span style="color: #000088;">$bracket</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: #666666; font-style: italic;">/*
   * @call $var-&gt;listemails(@params);
   * @param string bracket: caracter separador entre emails, per defecte ';'
   * @return string: llista els emails
   */</span>
      <span style="color: #000088;">$ret</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$Sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'SELECT Email FROM '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Table</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">';'</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$Result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$Sql</span><span style="color: #339933;">,</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">DB_Link</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;">$Result</span><span style="color: #009900;">&#41;</span>
      <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_assoc</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$Result</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
         <span style="color: #000088;">$ret</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Email'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$bracket</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #b1b100;">return</span> <span style="color: #000088;">$ret</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> addemail<span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #666666; font-style: italic;">/*
   * @call $var-&gt;addemial(@params);
   * @param string email: email a insertar
   * @return : 'true' si sha pogut insertar, 'false' si ja existeix
   */</span>
      <span style="color: #000088;">$Sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'INSERT INTO '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Table</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;(Email) VALUES ('&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$email</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;') ;&quot;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$Result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$Sql</span><span style="color: #339933;">,</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">DB_Link</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;">mysql_affected_rows</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">DB_Link</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;=</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;">true</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</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> delEmail<span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #666666; font-style: italic;">/*
   * @call $var-&gt;delEmail(@params);
   * @param string email: email a eliminar
   * @return: 'true' i s'ha pogut eliminar, 'false' si no s'ha trobat en el llistat
   */</span>
      <span style="color: #000088;">$Sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'DELETE FROM '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Table</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; WHERE Email='&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$email</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;';&quot;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$Result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$Sql</span><span style="color: #339933;">,</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">DB_Link</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;">mysql_affected_rows</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">DB_Link</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;=</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;">true</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h3>Ejemplo de uso</h3>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$NewsLetter</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SimpleNewsLetter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'localhost'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'user'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'password'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'database'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$NewsLetter</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createtable</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Newsletter'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;br /&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$NewsLetter</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addemail</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'prova@hotmail.com'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Insert'</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'alredy exist'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;br /&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$NewsLetter</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">delEmail</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'prova@hotmail.com'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'email eliminado'</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'no se ha encotrado email'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$NewsLetter</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addemail</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'prova@hotmail.com'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Insert'</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'alredy exist'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$NewsLetter</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addemail</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'prova@hotmail.com'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Insert'</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'alredy exist'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$NewsLetter</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addemail</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'prova2@hotmail.com'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Insert'</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'alredy exist'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;br /&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$NewsLetter</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">listemails</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.webserveis.com/195/clase-para-crear-newsletter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Comentar el codigo</title>
		<link>http://www.webserveis.com/163/comentar-el-codigo/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=comentar-el-codigo</link>
		<comments>http://www.webserveis.com/163/comentar-el-codigo/#comments</comments>
		<pubDate>Sat, 04 Feb 2012 23:36:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programación web]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.webserveis.com/?p=163</guid>
		<description><![CDATA[Una buena practica es comentar nuestro propio código. Para comentar un archivo /* * Descripción del codigo * * PHP version 5.0 * * Licencia * *@ Category CategoryName *@author autor original * @copyright 2012 empresa *@license http://www.liciensia.com *@version *@link http://www.webserveis.com *@usage */ Para comentar un bloque podemos usar lo siguiente /* * Descripción del [...]]]></description>
			<content:encoded><![CDATA[<p>Una buena practica es comentar nuestro propio código.</p>
<p>Para comentar un archivo</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/*
*  Descripción del codigo
*
* PHP version 5.0
*
* Licencia
*
*@ Category CategoryName
*@author autor original
* @copyright 2012 empresa
*@license http://www.liciensia.com
*@version
*@link http://www.webserveis.com
*@usage
*/</span></pre></div></div>

</p>
<p>Para comentar un bloque podemos usar lo siguiente</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/*
* Descripción del comentario
* Segunda linia del comentario
* Tercera linia del comentario
*/</span></pre></div></div>

</p>
<p>Si creamos una función podemos comentar sus variables y el retorno, usamos @param y @return</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/*
Descripción de la función
@param string $url    url of the requested script
@param array $data    hash array of request variables
@return returns a hash array with response content and headers in the following form:
array (&amp;amp;amp;#039;content&amp;amp;amp;#039;=&gt;&amp;amp;amp;#039;&lt;html&gt;&lt;/html&gt;&amp;amp;amp;#039;
, &amp;amp;amp;#039;headers&amp;amp;amp;#039;=&gt;array (&amp;amp;amp;#039;HTTP/1.1 200 OK&amp;amp;amp;#039;, &amp;amp;amp;#039;Connection: close&amp;amp;amp;#039;, ...)
)
*/</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.webserveis.com/163/comentar-el-codigo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Consejos para optimizar PHP II</title>
		<link>http://www.webserveis.com/160/consejos-para-optimizar-php-ii/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=consejos-para-optimizar-php-ii</link>
		<comments>http://www.webserveis.com/160/consejos-para-optimizar-php-ii/#comments</comments>
		<pubDate>Sat, 04 Feb 2012 22:55:02 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programación web]]></category>
		<category><![CDATA[optimizacion]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.webserveis.com/?p=160</guid>
		<description><![CDATA[Para mejorar la velocidad una página web se pueden hacer muchas cosas, cómo comprimir los archivos a GZIP, comprimir nuestros archivos CSS y javascript, hacer menos consultas HTTP (agrupando archivos) y un largo etc. Pero otra forma és mejorando la velocidad del código PHP. Esto hace que la carga del servidor sea menor y que [...]]]></description>
			<content:encoded><![CDATA[<p>Para mejorar la velocidad una página web se pueden hacer muchas cosas, cómo comprimir los archivos a <span style="color: #339966;"><strong>GZIP</strong></span>, comprimir nuestros archivos CSS y javascript, hacer menos consultas HTTP (agrupando archivos) y un largo etc. Pero otra forma és mejorando la velocidad del código PHP. Esto hace que la carga del servidor sea menor y que Google indexe mejor nuestro sitio al condicionar el PageRank a la velocidad de carga. Para esto, unos sencillos trucos para mejorar el código*:</p>
<p>- <em>implode </em>y <em>join</em>: <span style="color: #339966;"><strong>implode </strong></span>es un 5% más rápida.</p>
<p>- <em>for</em> y <em>while</em>: <span style="color: #339966;"><strong>for </strong></span>és un 4% más rapido.</p>
<p>- <em>echo</em> y <em>print</em>:</p>
<p><em>echo ‘foo’.&#8217;bar’.&#8217;foo’.&#8217;bar’ </em>vs <em>print ‘foo’.&#8217;bar’.&#8217;foo’.&#8217;bar’</em> : echo es un 4% más rapido</p>
<p><span style="color: #339966;"><em>echo ‘foo’.&#8217;bar’.&#8217;foo’.&#8217;bar</em>‘</span> vs <em>$a=’foo’;$b=’var’; echo $a.$b.$a.$b</em> : sin variables és un 300% más rapido</p>
<p>- <em>sizeof </em>y <em>count</em>: <span style="color: #339966;"><strong>count </strong></span>es un 12% más rápida.</p>
<p>- <em>is_int</em> y <em>is_integer</em>:<strong><span style="color: #339966;"> is_int</span></strong> es un 9% más rápida.</p>
<p>- <span style="color: #339966;"><strong><em>isSet</em> </strong></span>y <em>empty</em>: Los dos son identicos, pero cuidado con:</p>
<p><em>is_array</em> de un array: 160% más lento<br /><em>is_array</em> de un valor nulo: 1078% más lento<br />(<em>isSet &amp;&amp; _array</em>) de un valor nulo: 542% (no se ejecuta el ‘is_array’) más lento</p>
<p>Por lo tanto, siempre comprovaremos si el valor existe antes de preguntar si es un array.</p>
<p>- <em>ini_alter</em> y<em> ini_set</em>:<span style="color: #339966;"><strong> ini_set</strong></span> es un 19% más rápida.</p>
<p>- <em>foreach</em> y <span style="color: #339966;"><strong><em>while</em></strong></span>:</p>
<p><em>foreach($foo as $key=&gt;$val) $foo[$key] .= “bar”;</em> vs. <em>while(list($key) = each($foo)) $foo[$key] .= “bar”;</em> : while és 211%más rápido</p>
<p><strong>Truco:</strong><br /><em> </em></p>
<p><em>$key = array_keys($foo);<br />$size = sizeOf($key);<br />for ($i=0; $i&lt;$size; $i++) $foo[$key[$i]] .= “bar”;</em></p>
<p>Esta forma és un 72% más rapida que ‘while’, por lo tanto un 263% mas rapida que ‘foreach’</p>
<p>- <em>preg_match</em> vs.<span style="color: #339966;"><strong><em> strpos</em></strong></span>: strpos és un 51% más rapido (strstr y ereg són aún más lentos).</p>
<p>-<span style="color: #339966;"><strong><em> if</em></strong></span> es más rápido que<em> switch/case</em>, y ligeramente más rápido es usar == que ===</p>
<p>- Si un metodo puede ser <span style="color: #339966;"><strong>static </strong></span>declararlo así. Es 4 veces más rápido.</p>
<p>- Incrementar una variable local indefinida és unas 9 veces más lento que una<span style="color: #339966;"><strong> pre-inicializada</strong></span>. Siempre inicializar todas las variables.</p>
<p>- <strong>LO MÁS IMPORTANTE</strong>: no usar funciones dentro de loops. Por ejemplo:</p>
<p><span style="color: #339966;"><strong><em>$size = count($x); </em></strong></span><em><span style="color: #339966;"><strong>for ($i=0; $i&lt;$size; $i++)</strong></span> vs. for ($i=0; $i&lt;<strong>count</strong>($x); $i++)</em> : pre-calcular el tamaño és entre un 1500% i47940% más rapido (dependiendo del tipo de dato pre-calculado).</p>
<p>&nbsp;</p>
<p>Aplicando todas estas tecnicas podemos aumentar considerablemente el rendimiento del PHP.</p>
<p>Vía: <a href="http://www.phpbench.com/">PHP Benchmark</a> y <a href="http://www.sindikos.com/2011/04/optimiza-tu-codigo-php/" target="_blank">sindikos</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.webserveis.com/160/consejos-para-optimizar-php-ii/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Consejos para optimizar PHP</title>
		<link>http://www.webserveis.com/157/consejos-para-optimizar-php/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=consejos-para-optimizar-php</link>
		<comments>http://www.webserveis.com/157/consejos-para-optimizar-php/#comments</comments>
		<pubDate>Sat, 04 Feb 2012 22:48:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programación web]]></category>
		<category><![CDATA[optimizacion]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.webserveis.com/?p=157</guid>
		<description><![CDATA[Variables: No declares variables que no se vayan a usar ya que ocupan memoria. Utiliza constantes para aquellos valores que serán fijos a lo largo de la ejecución. A la hora de declarar variables siempre es preferible usar variables estáticas. Intenta evitar el uso de variables globales. Unset: Aunque PHP dispone de un Garbage Collector [...]]]></description>
			<content:encoded><![CDATA[<ul>
<li><strong>Variables</strong>: No declares variables que no se vayan a usar ya que ocupan memoria. Utiliza <span style="color: #339966;"><strong>constantes </strong></span>para aquellos valores que serán fijos a lo largo de la ejecución. A la hora de declarar variables siempre es preferible usar variables estáticas. Intenta evitar el uso de variables globales.</li>
<li><strong>Unset</strong>: Aunque PHP dispone de un Garbage Collector (liberador de memoria) no esta de mas usar la función <span style="color: #339966;"><strong>unset </strong></span>para eliminar variables y aumentar la memoria disponible, sobretodo cuando se usan arrays o variables extensas en servidores limitados.</li>
<li>Comparaciones: Los <strong>switch </strong>/ case usan mas ciclos de procesador que los<span style="color: #339966;"><strong> if / else</strong></span>, por lo tanto usa estos últimos siempre que puedas.</li>
<li><strong>Bucles</strong>: Un bucle <strong>for </strong>es mas lento que un <strong>while</strong>, que a su vez es mas lento que un<span style="color: #339966;"><strong> do..while</strong></span>. Debes evitar que la condición de parada de tus bucles sea una función, mejor una variable donde se guarde el valor de la función previamente. Revisa tus bucles y elimina aquellos que realmente no son necesarios.</li>
<li><strong>Inclusiones</strong>: Aunque las funciones<strong> include_once()</strong> y <strong>require_once()</strong> son muy útiles para evitar cargar el mismo script repetidas veces, su costo es muy alto. Revisa tu código e intenta usar <span style="color: #339966;"><strong>include()</strong></span> y<span style="color: #339966;"><strong> require()</strong></span> en su lugar.</li>
<li>Utiliza <strong>HTML </strong>antes que <strong>PHP</strong>: Cuando tengas que escribir código <span style="color: #339966;"><strong>HTML </strong></span>evita usar funciones PHP, como echo o print, salvo en casos en que sea indispensable.</li>
<li><strong>Comillas en PHP</strong>: Usa siempre que puedas las comillas <span style="color: #339966;"><strong>simples </strong></span>ya que a diferencia de las <strong>dobles</strong>, que interpolan los valores de las variables, estas solo interpretan literales, con la consiguiente mejora de procesamiento. Además debes evitar el uso del símbolo del dolar sin escapar (\$) entre comillas dobles ya que ralentiza el código enormemente.</li>
<li><strong>Comprobar existencia de variables:</strong> Cuando se necesite verificar la existencia de variables usaremos<span style="color: #339966;"><strong> isset()</strong></span> antes que<strong> empty()</strong> o <strong>is_array()</strong>, ya que la primera es la mas eficiente.</li>
<li><strong>Operador ===: </strong>Cuando compares dos variables del mismo tipo intenta evitar el operador ===, ya que a diferencia de <span style="color: #339966;"><strong>==</strong></span> que solo compara valores, este además compara el tipo de variable.</li>
<li><strong>Reporte de errores:</strong> Para usar el máximo nivel de error en tu log del debug usa <span style="color: #339966;"><strong>E_STRICT</strong></span> como nivel de error.</li>
<li><strong>Memoria y velocidad:</strong> Para comprobar la velocidad y la memoria que consume tu código te serán útiles las funciones <span style="color: #339966;"><strong>memory_get_usage()</strong></span> y <span style="color: #339966;"><strong>microtime()</strong></span>.</li>
<li><strong>Muchas funciones tienen un alias</strong>. Evita usar estos y llama directamente a la función original. Aquí tienes algunos alias(derecha) y su correspondiente función (izquierda):
<ul>
<li>die -&gt; <span style="color: #339966;">exit</span></li>
<li>diskfreespace -&gt; <span style="color: #339966;">disk_free_space</span></li>
<li>fputs -&gt; <span style="color: #339966;">fwrite</span></li>
<li>chop -&gt; <span style="color: #339966;">rtrim</span></li>
<li>ini_alter -&gt;<span style="color: #339966;"> ini_set</span></li>
<li>strchr -&gt; <span style="color: #339966;">strstr</span></li>
<li>sizeof -&gt; <span style="color: #339966;">count</span></li>
<li>close -&gt; <span style="color: #339966;">closedir</span></li>
<li>is_writeable -&gt;<span style="color: #339966;"> is_writable</span></li>
<li>join -&gt; <span style="color: #339966;">implode</span></li>
<li>pos -&gt; <span style="color: #339966;">current</span></li>
<li>dir -&gt; <span style="color: #339966;">getdir</span></li>
<li>rewind -&gt; <span style="color: #339966;">rewinddir</span></li>
</ul>
</li>
<li><strong>Incrementos: </strong>Cuando sea posible, siempre que incrementamos una variable usaremos el modo del modo <span style="color: #339966;"><strong>++$i</strong></span>(primero incrementa luego usa) antes que<strong> $i++</strong>(primero usa luego incrementa), ya que el primero usa 3 opcodes a diferencia de los 4 del segundo.</li>
<li><strong>Imprimir textos:</strong> Siempre que tengas que imprimir texto en PHP, usa la función <span style="color: #339966;"><strong>echo </strong></span>antes que <strong>print</strong>. La primera es mas rápida.</li>
<li><strong>Expresiones regulares:</strong> Intenta usar <strong>regexp </strong>solo cuando sea necesario, ya que aunque ahorran trabajo, su procesado es mas lento.</li>
<li><strong>Separaciones:</strong> Es conveniente usar<span style="color: #339966;"><strong> explode()</strong></span> antes que <strong>split()</strong>, ya que esta ultima permite el uso de expresiones regulares y la primera no.</li>
<li><strong>Random:</strong> Para generar valores aleatorios usaremos las funciones de la familia <span style="color: #339966;"><strong>mt_rand() </strong></span>que utiliza un algoritmo de Mersenne Twister mucho más rápido y eficiente que la típica<strong> rand()</strong>.</li>
</ul>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webserveis.com/157/consejos-para-optimizar-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Funciones para convertir Fechas en PHP</title>
		<link>http://www.webserveis.com/151/funciones-para-convertir-fechas-en-php/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=funciones-para-convertir-fechas-en-php</link>
		<comments>http://www.webserveis.com/151/funciones-para-convertir-fechas-en-php/#comments</comments>
		<pubDate>Mon, 30 Jan 2012 19:35:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programación web]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.webserveis.com/?p=151</guid>
		<description><![CDATA[Algunas veces necesitamos convertir las fechas para almacenar en una base de datos, o bien recuperar una fecha de un campo DATE, DATETIME, TIMESTAMP y mostrarlo con el formato de fecha europea es decir dia/mes/año en cuentas de año/mes/dia, que es el formato de MYSQL o bien de fechas de Estados Unidos. Las funciones son [...]]]></description>
			<content:encoded><![CDATA[<p>Algunas veces necesitamos convertir las fechas para almacenar en una base de datos, o bien recuperar una fecha de un campo <span style="color: #3366ff;">DATE</span>, <span style="color: #3366ff;">DATETIME</span>, <span style="color: #3366ff;">TIMESTAMP </span>y mostrarlo con el formato de fecha europea es decir <span style="color: #3366ff;">dia/mes/año</span> en cuentas de <span style="color: #3366ff;">año/mes/dia</span>, que es el formato de MYSQL o bien de fechas de Estados Unidos.</p>
<p>Las funciones son las siguientes: Date2Eu: Convierte la fecha US a Europea Date2Us: Convierte la fecha Europea a US &#8220;MYSQL&#8221;</p>
<h3>Declaración de Date2Eu</h3>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> Date2Eu<span style="color: #009900;">&#40;</span><span style="color: #000088;">$date</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$date</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'-'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">,</span><span style="color: #000088;">$date</span><span style="color: #339933;">,</span><span style="color: #000088;">$count</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$count</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$bracket_out</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'-'</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">else</span> <span style="color: #000088;">$bracket_out</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/'</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: #0000ff;">&quot;/([0-9]{4})\/([0-9]{2})\/([0-9]{2})/i&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$3</span>&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$bracket_out</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$2</span>&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$bracket_out</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$1</span>&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$date</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>Declaración de Date2Us</h3>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> Date2Us<span style="color: #009900;">&#40;</span><span style="color: #000088;">$date</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$date</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'-'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">,</span><span style="color: #000088;">$date</span><span style="color: #339933;">,</span><span style="color: #000088;">$count</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$count</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$bracket_out</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'-'</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">else</span> <span style="color: #000088;">$bracket_out</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/'</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: #0000ff;">&quot;/([0-9]{2})\/([0-9]{2})\/([0-9]{4})/i&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$3</span>&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$bracket_out</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$2</span>&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$bracket_out</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$1</span>&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$date</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>Uso de la funciones</h3>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> Date2Eu<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'2012/01/04'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> Date2Us<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'01/04/2012'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> Date2Eu<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'2012-01-04'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> Date2Us<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'01-04-2012'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.webserveis.com/151/funciones-para-convertir-fechas-en-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Funcion br2nl en php</title>
		<link>http://www.webserveis.com/149/funcion-br2nl-en-php/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=funcion-br2nl-en-php</link>
		<comments>http://www.webserveis.com/149/funcion-br2nl-en-php/#comments</comments>
		<pubDate>Thu, 26 Jan 2012 11:31:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[PHP Snippets]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php-snippet]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://www.webserveis.com/?p=149</guid>
		<description><![CDATA[PHP carece de la función inversa de nl2br, la funcion nl2br de php convierte todos los saltos de linea a salto de linea html &#60;br /&#62; Por eso la función siguiente br2nl, conviete los &#60;br /&#62; a salto de linea Declaración de la función br2nl function br2nl&#40;$string, $line_break=PHP_EOL&#41; &#123; $patterns = array&#40;&#34;/(&#60;br&#62;&#124;&#60;br \/&#62;&#124;&#60;br\/&#62;)\s*/i&#34;,&#34;/(\r\n&#124;\r&#124;\n)/&#34;&#41;; $replacements = array&#40;PHP_EOL,$line_break&#41;; [...]]]></description>
			<content:encoded><![CDATA[<p>PHP carece de la función inversa de nl2br, la funcion nl2br de php convierte todos los saltos de linea a salto de linea html &lt;br /&gt;<br />
<br />
Por eso la función siguiente br2nl, conviete los &lt;br /&gt; a salto de linea
</p>
<h3>Declaración de la función br2nl</h3>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> br2nl<span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #339933;">,</span> <span style="color: #000088;">$line_break</span><span style="color: #339933;">=</span>PHP_EOL<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$patterns</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/(&lt;br&gt;|&lt;br \/&gt;|&lt;br\/&gt;)\s*/i&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;/(<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>|<span style="color: #000099; font-weight: bold;">\r</span>|<span style="color: #000099; font-weight: bold;">\n</span>)/&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$replacements</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>PHP_EOL<span style="color: #339933;">,</span><span style="color: #000088;">$line_break</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$patterns</span><span style="color: #339933;">,</span> <span style="color: #000088;">$replacements</span><span style="color: #339933;">,</span> <span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$string</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p></p>
<h3>Uso de la función br2nl</h3>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> br2nl<span style="color: #009900;">&#40;</span><span style="color: #000088;">$Texto</span><span style="color: #009900;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.webserveis.com/149/funcion-br2nl-en-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Obtener valores por $_GET en php</title>
		<link>http://www.webserveis.com/147/obtener-valores-por-_get-en-php/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=obtener-valores-por-_get-en-php</link>
		<comments>http://www.webserveis.com/147/obtener-valores-por-_get-en-php/#comments</comments>
		<pubDate>Wed, 25 Jan 2012 20:17:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[PHP Snippets]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php-snippet]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://www.webserveis.com/?p=147</guid>
		<description><![CDATA[Cuando tenenmos que obtener valores por la url, la menera correcta seria la siguiente $start = &#40;isset&#40;$_GET&#91;'num'&#93;&#41; &#38;&#38; is_numeric&#40;$_GET&#91;'num'&#93;&#41;&#41;? &#40;int&#41;$_GET&#91;'num'&#93;:die&#40;&#34;Hacking Attempt!&#34;&#41;;]]></description>
			<content:encoded><![CDATA[<p>Cuando tenenmos que obtener valores por la url, la menera correcta seria la siguiente</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$start</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'num'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">is_numeric</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'num'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>? <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'num'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">:</span><span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Hacking Attempt!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.webserveis.com/147/obtener-valores-por-_get-en-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cómo ocultar la barra de navegación en tus aplicaciones web mobile con JavaScript</title>
		<link>http://www.webserveis.com/145/como-ocultar-la-barra-de-navegacion-en-tus-aplicaciones-web-mobile-con-javascript/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=como-ocultar-la-barra-de-navegacion-en-tus-aplicaciones-web-mobile-con-javascript</link>
		<comments>http://www.webserveis.com/145/como-ocultar-la-barra-de-navegacion-en-tus-aplicaciones-web-mobile-con-javascript/#comments</comments>
		<pubDate>Sun, 22 Jan 2012 14:27:45 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[IOS Web Snippets]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[IOS]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[mobile-snippet]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://www.webserveis.com/?p=145</guid>
		<description><![CDATA[Los navegadores de IOS y android, muestran la toolbar en la posición superior de la pantalla, reduciendo el espacio visible de la pantalla de los dispositivos moviles, para ocultar esa barra lo podemos hacer mediante javascript Función ocultar barra de navegación window.addEventListener&#40;'load', function&#40;&#41; &#123; setTimeout&#40;scrollTo, 0, 0, 1&#41;; &#125;, false&#41;;]]></description>
			<content:encoded><![CDATA[<p>Los navegadores de IOS y android, muestran la toolbar en la posición superior de la pantalla, reduciendo el espacio visible de la pantalla de los dispositivos moviles, para ocultar esa barra lo podemos hacer mediante javascript</p>
<p></p>
<h3>Función ocultar barra de navegación</h3>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">window.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'load'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    setTimeout<span style="color: #009900;">&#40;</span>scrollTo<span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.webserveis.com/145/como-ocultar-la-barra-de-navegacion-en-tus-aplicaciones-web-mobile-con-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Prevenir el ajusto de texto en rotar</title>
		<link>http://www.webserveis.com/143/prevenir-el-ajusto-de-texto-en-rotar/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=prevenir-el-ajusto-de-texto-en-rotar</link>
		<comments>http://www.webserveis.com/143/prevenir-el-ajusto-de-texto-en-rotar/#comments</comments>
		<pubDate>Sun, 22 Jan 2012 14:17:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[IOS Web Snippets]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[IOS]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Webkit]]></category>

		<guid isPermaLink="false">http://www.webserveis.com/?p=143</guid>
		<description><![CDATA[Cuando rotamos un iPhone, iTouch, Ipad, Android, blackberry etc&#8230; El navegador web del movil, detecta la rotación del dispositivo y ajusta automaticamente el texto, aumentando su tamaño o reduciendolo. Para prevenir ese efecto podemos usar una regla css para el motor webkit -webkit-text-size-adjust:none; Regla css body &#123; -webkit-text-size-adjust:none; &#125;]]></description>
			<content:encoded><![CDATA[<p>Cuando rotamos un iPhone, iTouch, Ipad, Android, blackberry etc&#8230; El navegador web del movil, detecta la rotación del dispositivo y ajusta automaticamente el texto, aumentando su tamaño o reduciendolo.<br />
Para prevenir ese efecto podemos usar una regla css para el motor webkit -webkit-text-size-adjust:none;</p>
<p></p>
<h3>Regla css</h3>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">body <span style="color: #00AA00;">&#123;</span>
	-webkit-text-size-adjust<span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.webserveis.com/143/prevenir-el-ajusto-de-texto-en-rotar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Definición de viewport para paginas web moviles</title>
		<link>http://www.webserveis.com/138/definicion-de-viewport-para-paginas-web-moviles/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=definicion-de-viewport-para-paginas-web-moviles</link>
		<comments>http://www.webserveis.com/138/definicion-de-viewport-para-paginas-web-moviles/#comments</comments>
		<pubDate>Sun, 22 Jan 2012 13:21:45 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Maquetación web]]></category>
		<category><![CDATA[WebDev Mobile]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[IOS]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[WebApp]]></category>

		<guid isPermaLink="false">http://www.webserveis.com/?p=138</guid>
		<description><![CDATA[Cuantas veces cuando visitas un sitioweb con tu smarthphone, Iphone, Android, blackberry, lo ves como un thubmanail? La razón es porque el desenvolupamiento de la página web, han oblidado de definir el viewport. Con el viewport podemos definir lo siguiente: Tamaño de la pagina web visualizado en el dispositivo móvil Escala inicial de zoom Escala [...]]]></description>
			<content:encoded><![CDATA[<p>Cuantas veces cuando visitas un sitioweb con tu smarthphone, Iphone, Android, blackberry, lo ves como un thubmanail? La razón es porque el desenvolupamiento de la página web, han oblidado de definir el viewport.</p>
<h3>Con el viewport podemos definir lo siguiente:</h3>
<ul>
<li>Tamaño de la pagina web visualizado en el dispositivo móvil </li>
<li>Escala inicial de zoom</li>
<li>Escala máxima de zoom</li>
<li>Prevenir que el usuario puede hacer zoom en el contenido</li>
</ul>
<p>Definición básica de un viewport</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width&quot; /&gt;</pre></div></div>

<p>En la zona <span style="color: #3366ff;">head</span> de nuestras paginas deberemos poner el metatag siguiente</p>
</p>
<h3>Atributos para el viewport</h3>
<p><strong>width: </strong>Definimos la anchura del viewport, puede ser un rango numerico entre 200 a 10000 pixeles o bien con la valor especial &#8220;device-width&#8221;: se obitene el valor de la anchura del dispositivo movil automáticamente.</p>
<p><strong>height: </strong>Definimos la altura del viewport, puede ser un rango numerico entre 223 a 10000 pixeles o bien con  el valor especial &#8220;device-height&#8221;, se obtiene el valor de la altura del dispositivo movil automáticamente.</p>
<p><strong>initial-scale:</strong> La escala inicial que se visualizará la página web movil. El rango es determinado entre los atributos minimum-scale y maximum-scale.</p>
<p><strong>minimum-scale: </strong>Especifica la escala minima del viewport, por defecto es 0.25, y podemos usar un rango de 0 a 10.0</p>
<p><strong>maximum-scale:</strong> Especifica la escala máxima del viewport, por defecto es 1.6, y podemos usar un rango de 0 a 10.0</p>
<p><strong>user-scalable: </strong> Determina si el usuario puede augmentar &#8220;zoom&#8221; el contenido, puede ser &#8220;yes&#8221; o bien &#8220;no&#8221;</p>
</p>
<h3>Ejemplo de definición de viewport</h3>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no&quot; /&gt;</pre></div></div>

<p>la anchura se detecta automaticamente, escala inicial 1x, maxima escala que el usuario puede aumentar es 1 y finalmente le especificamos que el usuario no puede hacer zoom del contenido.</p>
</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1, maximum-scale=3, user-scalable=yes&quot; /&gt;</pre></div></div>

<p>la anchura se detecta automaticamente, escala inicial 1x, máxima escala que el usuario puede aumentar es 3 y finalmente le especificamos que el usuario puede hacer zoom del contenido.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webserveis.com/138/definicion-de-viewport-para-paginas-web-moviles/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

