<?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>rails y más cosas &#187; php</title>
	<atom:link href="http://www.railsymas.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.railsymas.com</link>
	<description>Nuevas Tecnologías</description>
	<lastBuildDate>Sat, 28 Jan 2012 10:23:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Php5, sí o sí</title>
		<link>http://www.railsymas.com/2009/10/31/php5-si-o-si/</link>
		<comments>http://www.railsymas.com/2009/10/31/php5-si-o-si/#comments</comments>
		<pubDate>Sat, 31 Oct 2009 17:45:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.railsymas.com/?p=850</guid>
		<description><![CDATA[Ya hemos alcanzado la versión 5.3 de php y se va deslumbrando en el horizonte la versión 6.0. Php al igual que java son lenguajes de programación con un número enorme de programadores, quizas los dos lenguajes con más apoyo entre la comunidad informática. Muchas veces ambas comunidades entran en diversos foros, en discusiones acaloradas [...]]]></description>
			<content:encoded><![CDATA[<p> Ya hemos alcanzado la versión 5.3 de php y se va deslumbrando en el horizonte la versión 6.0.  Php al igual que java son lenguajes de programación con un número enorme de programadores, quizas los dos lenguajes con más apoyo entre la comunidad informática. </p>
<p><span id="more-850"></span></p>
<p>Muchas veces ambas comunidades entran en diversos foros, en discusiones acaloradas sobre cual es mejor o peor según que sitiuaciones, o contextos de aplicación. No voy a entrar en esos temas, ya  hay muchos foros y discusiones sobre el tema desde hace años. Lo que voy a comentar esta en relación sobre las necesidades de php actuales y en el futuro.</p>
<p>Hay una gran cantidad de informáticos aferrados todavía a la versión de php4, si bien es cierto que la mayoría de hostings dan la opción al usuario de elegir entre la versión de php4 y php5 para poder desplegar las aplicaciones correspondientes. Algo lógico para establecer un tiempo de transición entre la versión 4 y 5, ha propiciado que la forma de desarrollar de algunas empresas y desarrolladores se limite a la preocupación solamente de mantener una compatibilidad con la versión php5.</p>
<p>Lo que quiero decir es que todo lenguaje o versión tiene un ciclo, los lenguajes o la experiencia laboral en un lenguaje es efímera. Desarrollar en php5 no es sólo que funcione en php5, sino adoptar una metodología de POO avanzada con patrones de diseño y un acceso a bases de datos con orm tipo propel doctrine u otros &#8230;</p>
<p>Ventajas de todo esto, se da un impulso al lenguaje php, permitiendo optimizar y automatizar las tareas repetitivas para centrarse en detalles expecíficos de cada aplicación.</p>
<p>Enlace a gophp5 proyectos que apoyan php5<br />
<a href="http://gophp5.org" title="Support GoPHP5.org"><br />
<img src="http://gophp5.org/sites/gophp5.org/buttons/goPHP5-080x26.png" height="26" width="80"  /><br />
</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.railsymas.com/2009/10/31/php5-si-o-si/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>php5 clonación de objetos  __clone</title>
		<link>http://www.railsymas.com/2009/08/17/php5-clonacion-de-objetos-__clone/</link>
		<comments>http://www.railsymas.com/2009/08/17/php5-clonacion-de-objetos-__clone/#comments</comments>
		<pubDate>Mon, 17 Aug 2009 22:03:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.railsymas.com/?p=458</guid>
		<description><![CDATA[En este tutorial vamos a poner un ejemplo de como php5 permite la clonación de objetos de una forma fácil y sencilla. Creamos una clase Coche con una serie de propiedades &#8220;modelo , número de puertas y 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 [...]]]></description>
			<content:encoded><![CDATA[<p>En este tutorial vamos a poner un ejemplo de como php5 permite la clonación de objetos de una forma fácil y sencilla. </p>
<p>Creamos una clase Coche con una serie de propiedades &#8220;modelo , número de puertas y </p>
<p><span id="more-458"></span></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
42
43
44
45
46
47
48
49
50
51
52
53
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
 <span style="color: #000000; font-weight: bold;">class</span> Coche
 <span style="color: #009900;">&#123;</span>
 	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$numeroPuertas</span><span style="color: #339933;">;</span>
 	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$color</span><span style="color: #339933;">;</span>
 	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$modelo</span><span style="color: #339933;">;</span>
&nbsp;
 	<span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$modelo</span><span style="color: #339933;">,</span><span style="color: #000088;">$color</span><span style="color: #339933;">,</span><span style="color: #000088;">$numeroPuertas</span><span style="color: #009900;">&#41;</span>
 	<span style="color: #009900;">&#123;</span>
 	   <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">modelo</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$modelo</span><span style="color: #339933;">;</span>
 	   <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">color</span> <span style="color: #339933;">=</span>  <span style="color: #000088;">$color</span><span style="color: #339933;">;</span>
 	   <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">numeroPuertas</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$numeroPuertas</span><span style="color: #339933;">;</span> 	
 	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
 	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getModelo <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
 	<span style="color: #009900;">&#123;</span>
 		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">modelo</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> getColor<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
 	<span style="color: #009900;">&#123;</span>
 		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">color</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> getNumeroPuertas<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
 	<span style="color: #009900;">&#123;</span>
 		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">numeroPuertas</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> __clone<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
 	<span style="color: #009900;">&#123;</span>
 		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;objeto clonado &lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
 	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
 <span style="color: #009900;">&#125;</span>
&nbsp;
 <span style="color: #666666; font-style: italic;">//creamos un nuevo objeto Coche</span>
&nbsp;
 <span style="color: #000088;">$coche1</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Coche<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;modelo1&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;azul&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;4&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #666666; font-style: italic;">//mostramos las características del </span>
&nbsp;
 <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;tenemos el modelo &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$coche1</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getColor</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; color &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$coche1</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getNumeroPuertas</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #000088;">$coche2</span> <span style="color: #339933;">=</span> clone <span style="color: #000088;">$coche1</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;tenemos el modelo &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$coche2</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getColor</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; color &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$coche2</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getNumeroPuertas</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p><img src="http://www.railsymas.com/wp-content/uploads/2009/08/clonadophp1.png" alt="clonadophp" title="clonadophp" width="579" height="265" class="alignnone size-full wp-image-464" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.railsymas.com/2009/08/17/php5-clonacion-de-objetos-__clone/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>php5  try catch excepciones</title>
		<link>http://www.railsymas.com/2009/08/16/php5-try-catch-excepciones/</link>
		<comments>http://www.railsymas.com/2009/08/16/php5-try-catch-excepciones/#comments</comments>
		<pubDate>Sun, 16 Aug 2009 18:50:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.railsymas.com/?p=431</guid>
		<description><![CDATA[Tutorial para la categoría php. Php5 incorpora el tratamiento de excepciones al igual que otros lenguajes como java , c++ etc&#8230; Utilizamos las excepcionse cuando nuestra aplicación tiene que controlar situaciones suceptibles de producir error. Uno de los ejemplos típicos es la división por cero, el interprete de php genera el warnning correspondiente &#8221; Warning: [...]]]></description>
			<content:encoded><![CDATA[<p>Tutorial para la categoría php.<br />
 Php5 incorpora el tratamiento de excepciones al igual que otros lenguajes como java , c++ etc&#8230;<br />
 Utilizamos las excepcionse cuando nuestra aplicación tiene que controlar situaciones suceptibles de producir error. Uno de los ejemplos típicos es la división por cero, el interprete de php genera el warnning correspondiente &#8221;<br />
Warning: Division by zero in&#8221;. Con el bloque de código try catch podemos controlar dicho error y mostrar el mensaje correspondiente. </p>
<p><span id="more-431"></span></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
42
43
44
45
46
47
48
49
50
51
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">class</span> Division
   <span style="color: #009900;">&#123;</span>
   	 <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$dividendo</span><span style="color: #339933;">;</span>
   	 <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$divisor</span><span style="color: #339933;">;</span>
&nbsp;
   	 <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$dividendo</span><span style="color: #339933;">,</span> <span style="color: #000088;">$divisor</span> <span style="color: #009900;">&#41;</span>
   	 <span style="color: #009900;">&#123;</span>
   	 	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dividendo</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$dividendo</span><span style="color: #339933;">;</span>
   	 	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">divisor</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$divisor</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> dividir <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#41;</span>
   	 <span style="color: #009900;">&#123;</span>
&nbsp;
     try
     <span style="color: #009900;">&#123;</span>	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">divisor</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
   	 	<span style="color: #009900;">&#123;</span>
   	 		<span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;no se puede dividir por cero&quot;</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;">return</span>  <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dividendo</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">divisor</span><span style="color: #339933;">;</span>
   	 	<span style="color: #009900;">&#125;</span>
     <span style="color: #009900;">&#125;</span>
     catch <span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span>
     <span style="color: #009900;">&#123;</span>
     	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/br&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$e</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/br&gt;&quot;</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
   	 <span style="color: #009900;">&#125;</span>  	 
&nbsp;
   <span style="color: #009900;">&#125;</span>  
&nbsp;
   <span style="color: #666666; font-style: italic;">//creamos un objeto de la clase división </span>
&nbsp;
   <span style="color: #000088;">$division1</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Division <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$division2</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Division <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
   <span style="color: #666666; font-style: italic;">//llamamos al método dividir del objeto $nuevo</span>
&nbsp;
   <span style="color: #000088;">$resultado</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$division1</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dividir</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;el ressultado es: &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$resultado</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
   <span style="color: #000088;">$resultado</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$division2</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dividir</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Se crean dos objetos de la clase División esos dos objetos el primero división 1,  sele pasan los valores correctos para una división y división 2   el divisor el valor cero. En el bloque try se pone el conjunto de instrucciones que se quieren proteger del error y finalmente en el catch hacemos el tratamiento de dicho error.</p>
<p><img src="http://www.railsymas.com/wp-content/uploads/2009/08/excepciones.png" alt="excepciones" title="excepciones" width="541" height="298" class="alignnone size-full wp-image-435" /></p>
<p>Vemos con en el primer caso con división 1 si sale el mensaje con el resultado mientras con división 2 se crea el objeto &#8220;Exception e&#8221; y se llama al método &#8220;getMessage&#8221; para obtener el correspondiente mensaje.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.railsymas.com/2009/08/16/php5-try-catch-excepciones/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>php5 destructores __destruct</title>
		<link>http://www.railsymas.com/2009/08/15/php5-destructores-__destruct/</link>
		<comments>http://www.railsymas.com/2009/08/15/php5-destructores-__destruct/#comments</comments>
		<pubDate>Sat, 15 Aug 2009 16:36:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.railsymas.com/?p=424</guid>
		<description><![CDATA[Php5 incorpora lo que se denomina en programación orientada a objetos métodos destructores, estos métodos tienen la Mediante la palabra reservada __destruct creamos el método destructor, este método no tiene que recibir ningun parámetro. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 [...]]]></description>
			<content:encoded><![CDATA[<p> Php5 incorpora lo que se denomina en programación orientada a objetos métodos destructores, estos métodos tienen la  </p>
<p>Mediante la palabra reservada __destruct creamos el método destructor, este método no tiene que recibir ningun parámetro.</p>
<p><span id="more-424"></span></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
42
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">class</span> Coche
  <span style="color: #009900;">&#123;</span>
  	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$modelo</span><span style="color: #339933;">;</span>
  	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$cv</span><span style="color: #339933;">;</span>
  	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$matricula</span><span style="color: #339933;">;</span>
&nbsp;
  	<span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$modelo</span><span style="color: #339933;">,</span><span style="color: #000088;">$cv</span><span style="color: #339933;">,</span><span style="color: #000088;">$matricula</span><span style="color: #009900;">&#41;</span>
  	<span style="color: #009900;">&#123;</span>
  		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">modelo</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$modelo</span><span style="color: #339933;">;</span>
  		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cv</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$cv</span><span style="color: #339933;">;</span>
  		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">matricula</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$matricula</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> getModelo <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  	<span style="color: #009900;">&#123;</span>
  		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">modelo</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> getCv <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  	<span style="color: #009900;">&#123;</span>
  		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cv</span><span style="color: #339933;">;</span>
  	<span style="color: #009900;">&#125;</span>
&nbsp;
  	<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: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;el coche es eliminado con matricula&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">matricula</span><span style="color: #339933;">;</span>
  	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">//creamos el objeto coche</span>
  <span style="color: #000088;">$coche</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Coche<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;modeloCoche&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;150&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;123E&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;mostramos el modelo&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$coche</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getModelo</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/br&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$coche</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p><img src="http://www.railsymas.com/wp-content/uploads/2009/08/desctructores1.png" alt="desctructores" title="desctructores" width="508" height="258" class="alignnone size-full wp-image-427" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.railsymas.com/2009/08/15/php5-destructores-__destruct/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>php5 constructores y herencia</title>
		<link>http://www.railsymas.com/2009/08/13/php5-constructores-y-herencia/</link>
		<comments>http://www.railsymas.com/2009/08/13/php5-constructores-y-herencia/#comments</comments>
		<pubDate>Thu, 13 Aug 2009 20:59:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.railsymas.com/?p=414</guid>
		<description><![CDATA[En anteriores post sobre php habíamos visto algun ejemplo relacionado con la programación orientada a objetos y la declaración de una clase en php4. Actualmente la versión más reciente de php es la cinco y en ella se ha dotado al lenguaje php de las características propias de un lenguaje POO. Para declarar la clase [...]]]></description>
			<content:encoded><![CDATA[<p>En anteriores post sobre php habíamos visto algun ejemplo relacionado con la programación orientada a objetos y la declaración de una clase en php4. Actualmente la versión más reciente de php es la cinco y en ella se ha dotado al lenguaje php de las características propias de un lenguaje POO. </p>
<p>Para declarar la clase utilizamos la palabra reservada &#8220;class&#8221; al igual que en la versión php4, pero el constructor de la clase utiliza para su declaración la palabra reservada &#8220;__construct&#8221; doble siguión bajo seguido. </p>
<p>Para que una clase hija herede las propiedades y los métodos de la clase padre se utiliza la palabra reservada &#8220;extends&#8221; en la declaración de la cabecera de la clase hija. </p>
<p>En la clase hija &#8220;Apellidos&#8221; desde su constructor se llama al constructor de la clase padre &#8220;Nombre&#8221; mediante<br />
 &#8220;Nombre:: __construct($nombre);&#8221;    Nombre de la clase padre :: __construct(lista de argumentos si los necesita);</p>
<p><span id="more-414"></span><br />
la declaración de las propiedades de la clase, vemos como en php5 no necesitamos la palabra reservada var como en php4 y simplemente con $nombrevarialble ya tenemos la propiedad creada. En la declaración de la propiedad podemos acompañar con los modificadores de ambito  &#8220;public&#8221;, &#8220;private&#8221; y &#8220;protected&#8221;</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
42
43
44
45
46
47
48
49
50
51
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
 <span style="color: #000000; font-weight: bold;">class</span> Nombre
 <span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$nombre</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$nombre</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nombre</span><span style="color: #339933;">=</span><span style="color: #000088;">$nombre</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> getNombre<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
     <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nombre</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> setNombre<span style="color: #009900;">&#40;</span><span style="color: #000088;">$nombre</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nombre</span><span style="color: #339933;">=</span><span style="color: #000088;">$nombre</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>   
&nbsp;
 <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
 <span style="color: #000000; font-weight: bold;">class</span> Apellidos <span style="color: #000000; font-weight: bold;">extends</span> Nombre
 <span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$apellidos</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$nombre</span><span style="color: #339933;">,</span><span style="color: #000088;">$apellidos</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">apellidos</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$apellidos</span><span style="color: #339933;">;</span>
&nbsp;
	 <span style="color: #666666; font-style: italic;">//llamamos la constructor padre</span>
	 Nombre<span style="color: #339933;">::</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$nombre</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> getApellidos<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
     <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getNombre</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">apellidos</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
 <span style="color: #009900;">&#125;</span>
&nbsp;
 <span style="color: #000088;">$ape</span><span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Apellidos<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;pepe&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;perez&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;el nombre del sujeto es &lt;/br&gt;&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$ape</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getApellidos</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p><img src="http://www.railsymas.com/wp-content/uploads/2009/08/construct.png" alt="construct" title="construct" width="528" height="334" class="alignnone size-full wp-image-418" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.railsymas.com/2009/08/13/php5-constructores-y-herencia/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Escritura de ficheros en php</title>
		<link>http://www.railsymas.com/2009/08/07/escritura-de-ficheros-en-php/</link>
		<comments>http://www.railsymas.com/2009/08/07/escritura-de-ficheros-en-php/#comments</comments>
		<pubDate>Fri, 07 Aug 2009 13:35:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.railsymas.com/?p=391</guid>
		<description><![CDATA[Escritura de ficheros en php En este ejemplo se puede ver como un formulario en html es el encargado de recoger una serie de campos de para enviarselor a un script de php. Se establece una constante mendiante &#8220;define&#8221; esa constantes se llama NOMBRE_FICHERO, mediante fopen abrimos el fichero para añadidura. Se crea un manejador [...]]]></description>
			<content:encoded><![CDATA[<p>Escritura de ficheros en php</p>
<p>En este ejemplo se puede ver como un formulario en html es el encargado de recoger una serie de campos de para enviarselor a un script de php.</p>
<p>Se establece una constante mendiante &#8220;define&#8221; esa constantes se llama NOMBRE_FICHERO, mediante fopen abrimos el fichero para añadidura. Se crea un manejador de fichero $fichero. Para escribir un fputs(manejador,variable o cadena de texto ) escribimos en el el fichero el valor del campo del formulario.</p>
<p>Si queremos mostrar en un html los datos que acabamos de grabar y los ya existentes, se llama a la función leer_campo($fichero) para leer los campos del fichero grabados y mosrtrarlos por pantalla</p>
<p>Tenemos </p>
<p><span id="more-391"></span></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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&lt;style type=&quot;text/css&quot;&gt;
&nbsp;
   th { 
       font-size:12px;
      }
&nbsp;
   td.azul { font-size:14px;
        color:blue;
       text-align:left; }
&nbsp;
   body { background-color:#E3C993; }	  
&nbsp;
   p { text-align:center; }	  
&nbsp;
&lt;/style&gt;
&lt;/head&gt;
&nbsp;
&lt;body&gt;
&lt;p&gt;
INFORMACI&amp;Oacute;N DE LOS ART&amp;Iacute;CULOS ALMACENADOS
&lt;/p&gt;
 &lt;table border=&quot;2&quot; cellpadding=&quot;2&quot; align=&quot;center&quot;&gt;
    &lt;tr&gt;
      &lt;th&gt;Código&lt;/th&gt;
      &lt;th&gt;Descripción&lt;/th&gt;
      &lt;th&gt;Precio de coste&lt;/th&gt;
      &lt;th&gt;Precio de venta&lt;/th&gt;
      &lt;th&gt;Stock actual&lt;/th&gt;
      &lt;th&gt;Stock mínimo&lt;/th&gt;
    &lt;/tr&gt;
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
   <span style="color: #000000; font-weight: bold;">function</span> leer_campo<span style="color: #009900;">&#40;</span><span style="color: #000088;">$fichero</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: #339933;">!</span><span style="color: #990000;">feof</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fichero</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
         <span style="color: #009900;">&#123;</span>
         <span style="color: #000088;">$buffer</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fgets</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fichero</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4096</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #666666; font-style: italic;">// Elimina el carácter de salto de línea chop</span>
         <span style="color: #000088;">$buffer</span> <span style="color: #339933;">=</span> <span style="color: #990000;">chop</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$buffer</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #666666; font-style: italic;">// Si la línea se ha quedado vacía </span>
         <span style="color: #666666; font-style: italic;">// no va a salir</span>
&nbsp;
         <span style="color: #009900;">&#125;</span>
      <span style="color: #b1b100;">else</span> <span style="color: #000088;">$buffer</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">return</span> <span style="color: #000088;">$buffer</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #666666; font-style: italic;">// Se abre el fichero para guardar los datos al final</span>
   <span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'NOMBRE_FICHERO'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'pedidos.dat'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$fichero</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span>NOMBRE_FICHERO<span style="color: #339933;">,</span> <span style="color: #0000ff;">'a'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #666666; font-style: italic;">// Se escribe en el fichero una línea por cada campo</span>
   <span style="color: #990000;">fputs</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fichero</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$codigo</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: #990000;">fputs</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fichero</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$descripcion</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: #990000;">fputs</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fichero</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$coste</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: #990000;">fputs</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fichero</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$venta</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: #990000;">fputs</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fichero</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$stock</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: #990000;">fputs</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fichero</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$minimo</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #666666; font-style: italic;">// Se cierra el fichero para que los datos queden guardados</span>
   <span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fichero</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #666666; font-style: italic;">// Se abre el fichero para leer los datos de los productos</span>
   <span style="color: #000088;">$fichero</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span>NOMBRE_FICHERO<span style="color: #339933;">,</span> <span style="color: #0000ff;">'r'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #666666; font-style: italic;">// Se recorre el fichero para mostrar el nuevo contenido</span>
   <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">feof</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fichero</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;tr&gt;&quot;</span><span style="color: #339933;">;</span>
      <span style="color: #666666; font-style: italic;">// Se leen los seis campos</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;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">6</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>
&nbsp;
		 <span style="color: #000088;">$cadena</span><span style="color: #339933;">=</span>leer_campo<span style="color: #009900;">&#40;</span><span style="color: #000088;">$fichero</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;">$cadena</span><span style="color: #339933;">!=</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span>
		 <span style="color: #009900;">&#123;</span> 
          <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;td class='azul'&gt;&quot;</span><span style="color: #339933;">;</span>          
		  <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$cadena</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&lt;/td&gt;&quot;</span><span style="color: #339933;">;</span>
		  <span style="color: #009900;">&#125;</span>
&nbsp;
         <span style="color: #009900;">&#125;</span>
      <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/tr&gt;&quot;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #666666; font-style: italic;">// Se cierra el fichero</span>
   <span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fichero</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/table&gt;</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.railsymas.com/2009/08/07/escritura-de-ficheros-en-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>programación orientada a objetos en php</title>
		<link>http://www.railsymas.com/2009/07/15/programacion-orientada-a-objetos-en-php/</link>
		<comments>http://www.railsymas.com/2009/07/15/programacion-orientada-a-objetos-en-php/#comments</comments>
		<pubDate>Wed, 15 Jul 2009 15:05:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.railsymas.com/?p=243</guid>
		<description><![CDATA[Tenemos una clase Pagina_web con una serie de propiedades del objeto y varios métodos asociados a dicho objeto construyendo el esqueleto de la página web (&#8220;cabecera , cuerpo y pie&#8221;); La clase formulario_web hereda las propiedades y los métodos de la clase Pagina_web y extiende los suyos propios. creación del objeto nuevaPagina $nuevaPagina= new formulario_web(); [...]]]></description>
			<content:encoded><![CDATA[<p>Tenemos una clase Pagina_web con una serie de propiedades del objeto y varios métodos asociados a dicho objeto construyendo el esqueleto de la página web (&#8220;cabecera , cuerpo y pie&#8221;);</p>
<p>La clase formulario_web hereda las propiedades y los métodos de la clase Pagina_web y extiende los suyos propios.</p>
<p>creación del objeto  nuevaPagina $nuevaPagina= new formulario_web();</p>
<p><span id="more-243"></span></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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>
<span style="color: #000000; font-weight: bold;">class</span> Pagina_web
<span style="color: #009900;">&#123;</span>
 <span style="color: #666666; font-style: italic;">//definimos el titulo de la pagina</span>
  <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$titulo</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">function</span>  obtenerTitulo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">titulo</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">function</span> establecerTitulo<span style="color: #009900;">&#40;</span><span style="color: #000088;">$titulo</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;titulo por defecto&quot;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">titulo</span><span style="color: #339933;">=</span><span style="color: #000088;">$titulo</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">function</span> ponerCabecera<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
     <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;!DOCTYPE html PUBLIC <span style="color: #000099; font-weight: bold;">\&quot;</span>-//W3C//DTD XHTML 1.0 Transitional//EN<span style="color: #000099; font-weight: bold;">\&quot;</span> <span style="color: #000099; font-weight: bold;">\&quot;</span>http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;<span style="color: #000099; font-weight: bold;">\n</span>
     &lt;html xmlns=<span style="color: #000099; font-weight: bold;">\&quot;</span>http://www.w3.org/1999/xhtml<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;head&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;title&gt;&quot;</span><span style="color: #339933;">;</span>
	 <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">titulo</span><span style="color: #339933;">;</span>
	 <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/title&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;/head&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">function</span> ponerCuerpo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;body&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000000; font-weight: bold;">function</span> ponerPie<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
     <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/body&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
	 <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/html&gt;&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">//si utilizamos la palabra reservada final esa funcion no puede reescrita en las clases hijas</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">//herencia de clases</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Formulario_web <span style="color: #000000; font-weight: bold;">extends</span> Pagina_web
<span style="color: #009900;">&#123;</span>  
    <span style="color: #666666; font-style: italic;">//inicio de formulario pasamos el tipo de accion, pasamos el tipo de metodo  de envio y el nombre del formulario</span>
   <span style="color: #000000; font-weight: bold;">function</span> formulario_inicio <span style="color: #009900;">&#40;</span><span style="color: #000088;">$action</span><span style="color: #339933;">,</span><span style="color: #000088;">$method</span><span style="color: #339933;">,</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span> 
      <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&lt;form action=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">$action</span><span style="color: #000099; font-weight: bold;">\&quot;</span>  method=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">$method</span><span style="color: #000099; font-weight: bold;">\&quot;</span> name=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">$name</span><span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #666666; font-style: italic;">//indicamos el final del formulario</span>
   <span style="color: #000000; font-weight: bold;">function</span> formulario_fin<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/form&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #666666; font-style: italic;">//establecemos el campo input del formulario añadimos un salto tanto si tiene  campo valor como sino</span>
   <span style="color: #000000; font-weight: bold;">function</span>  formulario_input<span style="color: #009900;">&#40;</span><span style="color: #000088;">$type</span><span style="color: #339933;">,</span> <span style="color: #000088;">$name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #339933;">,</span><span style="color: #000088;">$salto</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>   
        <span style="color: #000088;">$cadena_auxiliar</span><span style="color: #339933;">;</span> 
   		<span style="color: #000088;">$cadena_auxiliar</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;input type=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">$type</span><span style="color: #000099; font-weight: bold;">\&quot;</span> name=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">$name</span><span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">//si tiene valor se lo ponemos como atributo</span>
		<span style="color: #b1b100;">if</span>  <span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #339933;">!=</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> 
		<span style="color: #000088;">$cadena_auxiliar</span><span style="color: #339933;">.=</span><span style="color: #0000ff;">&quot;value=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">$value</span><span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">//cerramos el imnput</span>
		<span style="color: #000088;">$cadena_auxiliar</span><span style="color: #339933;">.=</span><span style="color: #0000ff;">&quot;&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span> 
		<span style="color: #666666; font-style: italic;">//si necesita un salto despues del campo lo ponemos</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$cadena_auxiliar</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$salto</span><span style="color: #339933;">==</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
		  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/br&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">function</span> salto<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
     <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/br&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">function</span> mensaje<span style="color: #009900;">&#40;</span><span style="color: #000088;">$cadena</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
&nbsp;
	 <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$cadena</span>&lt;/br&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$nuevaPagina</span><span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> formulario_web<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//llamamos a los metodos de la clase padre</span>
<span style="color: #000088;">$nuevaPagina</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">establecerTitulo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Primera Web Php5&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$nuevaPagina</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ponerCabecera</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$nuevaPagina</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ponerCuerpo</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$nuevaPagina</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">formulario_inicio</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;index.php&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;get&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;formulario primero&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$nuevaPagina</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">mensaje</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;escribe tu nonbre&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$nuevaPagina</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">formulario_input</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;text&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;nombre&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$nuevaPagina</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">mensaje</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ecribe tu edad&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	   
<span style="color: #000088;">$nuevaPagina</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">formulario_input</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;text&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;edad&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	   
<span style="color: #000088;">$nuevaPagina</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">mensaje</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;introduce tu telefono:&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$nuevaPagina</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">formulario_input</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;text&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;telefono&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$nuevaPagina</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">salto</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;este formulario como te parece: &quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$nuevaPagina</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">salto</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$nuevaPagina</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">formulario_input</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;radio&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;me_parece&quot;</span> <span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;bueno&quot;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$nuevaPagina</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">mensaje</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;bueno&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$nuevaPagina</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">formulario_input</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;radio&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;me_parece&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;regular&quot;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$nuevaPagina</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">mensaje</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;regular&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$nuevaPagina</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">formulario_input</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;radio&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;me_parece&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;malo&quot;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$nuevaPagina</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">mensaje</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;malo&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$nuevaPagina</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">formulario_input</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;submit&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;enviar&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;enviar&quot;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&amp;nbsp<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$nuevaPagina</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">formulario_input</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;reset&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;borrar&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;borrar&quot;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 	   
<span style="color: #000088;">$nuevaPagina</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">formulario_fin</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$nuevaPagina</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ponerPie</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.railsymas.com/2009/07/15/programacion-orientada-a-objetos-en-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ajax y php 3 parte</title>
		<link>http://www.railsymas.com/2009/07/14/ajax-y-php-3-parte/</link>
		<comments>http://www.railsymas.com/2009/07/14/ajax-y-php-3-parte/#comments</comments>
		<pubDate>Tue, 14 Jul 2009 09:52:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.railsymas.com/?p=235</guid>
		<description><![CDATA[Para terminar tenemos el código del fichero php respuesta.php 1 2 3 4 5 6 7 8 9 10 11 12 &#60;? &#160; if &#40;isset&#40;$_POST&#41;&#41; &#123; $nombre=$_POST&#91;&#34;deporte&#34;&#93;; $apellidos=$_POST&#91;&#34;color&#34;&#93;; $correo=$_POST&#91;&#34;correo&#34;&#93;; &#160; echo &#34;{deporte:'$deporte', color:'$color', correo:'$correo'}&#34;; &#160; &#125; ?&#62;]]></description>
			<content:encoded><![CDATA[<p>Para terminar tenemos el código del fichero php respuesta.php</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>
&nbsp;
	<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;">$_POST</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>   
	    <span style="color: #000088;">$nombre</span><span style="color: #339933;">=</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;deporte&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	    <span style="color: #000088;">$apellidos</span><span style="color: #339933;">=</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;color&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	   <span style="color: #000088;">$correo</span><span style="color: #339933;">=</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;correo&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
	    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;{deporte:'<span style="color: #006699; font-weight: bold;">$deporte</span>', color:'<span style="color: #006699; font-weight: bold;">$color</span>', correo:'<span style="color: #006699; font-weight: bold;">$correo</span>'}&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.railsymas.com/2009/07/14/ajax-y-php-3-parte/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ajax y php  2 parte</title>
		<link>http://www.railsymas.com/2009/07/13/ajax-y-php-2-parte/</link>
		<comments>http://www.railsymas.com/2009/07/13/ajax-y-php-2-parte/#comments</comments>
		<pubDate>Mon, 13 Jul 2009 22:10:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.railsymas.com/?p=169</guid>
		<description><![CDATA[Código del fichero javascript validacion.js 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 42 43 44 45 46 47 48 49 50 [...]]]></description>
			<content:encoded><![CDATA[<p>Código del fichero javascript  validacion.js</p>
<p><span id="more-169"></span></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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// JavaScript Document</span>
&nbsp;
window.<span style="color: #000066;">onload</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>
  document.<span style="color: #660066;">forms</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">onsubmit</span><span style="color: #339933;">=</span>recogerFormulario<span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">var</span> selector<span style="color: #339933;">=</span>document.<span style="color: #660066;">forms</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  selector.<span style="color: #660066;">estilo</span>.<span style="color: #660066;">onchange</span><span style="color: #339933;">=</span>establecerEstilo<span style="color: #339933;">;</span>	 
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Definimos un constructor para los datos del formulario para quedar almacenados y trabajar con ellos</span>
<span style="color: #003366; font-weight: bold;">function</span> formulario <span style="color: #009900;">&#40;</span>deporte<span style="color: #339933;">,</span>color<span style="color: #339933;">,</span>correo<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
   <span style="color: #006600; font-style: italic;">//propiedad deporte de la clase</span>
   <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">deporte</span><span style="color: #339933;">=</span>deporte<span style="color: #339933;">;</span>
   <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">color</span><span style="color: #339933;">=</span>color<span style="color: #339933;">;</span>
   <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">correo</span><span style="color: #339933;">=</span>correo<span style="color: #339933;">;</span>
   <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">valido</span><span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
   <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">mensaje</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
   <span style="color: #006600; font-style: italic;">//asignar la propiedad de un objeto a una funcion externa </span>
   <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">validar</span><span style="color: #339933;">=</span>validar<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> recogerFormulario<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span> 
  <span style="color: #006600; font-style: italic;">//le pasamos los datos a las correspondientes funcion de comprobacion pasandole el nombre etc gracias al this del formulario </span>
&nbsp;
   chequeoCampos<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">deporte</span>.<span style="color: #660066;">value</span><span style="color: #339933;">,</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">color</span>.<span style="color: #660066;">value</span><span style="color: #339933;">,</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">correo</span>.<span style="color: #660066;">value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #006600; font-style: italic;">// return false;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> validar<span style="color: #009900;">&#40;</span>registro<span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span> 
&nbsp;
&nbsp;
	 <span style="color: #006600; font-style: italic;">//primero comprobamos que los campos del formulario no estan vacios </span>
	 <span style="color: #006600; font-style: italic;">//variable local que indica si todos los campos estan completos</span>
	 <span style="color: #003366; font-weight: bold;">var</span> completo<span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
	 <span style="color: #003366; font-weight: bold;">var</span> direccion<span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	 <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">deporte</span><span style="color: #339933;">==</span><span style="color: #003366; font-weight: bold;">null</span> <span style="color: #339933;">||</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">deporte</span>.<span style="color: #660066;">length</span><span style="color: #339933;">==</span><span style="color: #CC0000;">0</span> <span style="color: #009900;">&#41;</span>
	    <span style="color: #009900;">&#123;</span>  completo<span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
	 <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">color</span><span style="color: #339933;">==</span><span style="color: #003366; font-weight: bold;">null</span> <span style="color: #339933;">||</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">color</span>.<span style="color: #660066;">length</span><span style="color: #339933;">==</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span>
	 	<span style="color: #009900;">&#123;</span>   completo<span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
	 <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">correo</span><span style="color: #339933;">==</span><span style="color: #003366; font-weight: bold;">null</span> <span style="color: #339933;">||</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">correo</span>.<span style="color: #660066;">length</span><span style="color: #339933;">==</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span>
	 	<span style="color: #009900;">&#123;</span> completo<span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
     <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">correo</span>.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span> <span style="color: #339933;">||</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">correo</span>.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;@&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==-</span><span style="color: #CC0000;">1</span> <span style="color: #339933;">||</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">correo</span>.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot; &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">!=-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span>
	 <span style="color: #009900;">&#123;</span>
		direccion<span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span> 
	 <span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>completo<span style="color: #339933;">==</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span>direccion<span style="color: #339933;">==</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">valido</span><span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
	descodificarMensaje<span style="color: #009900;">&#40;</span>completo<span style="color: #339933;">,</span>direccion<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	 
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> descodificarMensaje<span style="color: #009900;">&#40;</span>completo<span style="color: #339933;">,</span>direccion<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> texto<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>completo<span style="color: #339933;">==</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>  texto<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;hay campos sin completar&quot;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
  <span style="color: #000066; font-weight: bold;">else</span>
  <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>direccion<span style="color: #339933;">==</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>  texto<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;la direccion de correo no es correcta&quot;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #009900;">&#125;</span>
&nbsp;
  mensaje<span style="color: #009900;">&#40;</span>texto<span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;red&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> 
&nbsp;
&nbsp;
<span style="color: #006600; font-style: italic;">//funcion encargada de mostrar el mensaje por pantalla en un determinado color</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> limpiar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> formulario<span style="color: #339933;">=</span>document.<span style="color: #660066;">forms</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
  formulario.<span style="color: #660066;">deporte</span>.<span style="color: #660066;">value</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
  formulario.<span style="color: #660066;">color</span>.<span style="color: #660066;">value</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
  formulario.<span style="color: #660066;">correo</span>.<span style="color: #660066;">value</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> mensaje<span style="color: #009900;">&#40;</span>texto<span style="color: #339933;">,</span>colores<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span> 
   <span style="color: #006600; font-style: italic;">//accedemos a la capa mensaje para escribir el codigo correspondiente</span>
   <span style="color: #003366; font-weight: bold;">var</span> msj<span style="color: #339933;">=</span>document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;mensaje&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
   <span style="color: #006600; font-style: italic;">//si no hay mensaje de error todo esta bien limpiamos los campos y si tenemos un mensaje anterior lo limpiamos</span>
   <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>texto<span style="color: #339933;">==</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span> limpiar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
       <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>msj.<span style="color: #660066;">hasChildNodes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #006600; font-style: italic;">//si tienes nodos hijos</span>
       <span style="color: #009900;">&#123;</span>
	     msj.<span style="color: #660066;">removeChild</span><span style="color: #009900;">&#40;</span>msj.<span style="color: #660066;">firstChild</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
       <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #006600; font-style: italic;">//en caso contrario cogemos y escribimos el mensaje correspondiente y en el color correpondiente</span>
   <span style="color: #000066; font-weight: bold;">else</span>
   <span style="color: #009900;">&#123;</span>  
&nbsp;
&nbsp;
   <span style="color: #006600; font-style: italic;">//determinamos las propiedades de estilo</span>
   msj.<span style="color: #660066;">style</span>.<span style="color: #660066;">color</span><span style="color: #339933;">=</span>colores<span style="color: #339933;">;</span>
   msj.<span style="color: #660066;">style</span>.<span style="color: #660066;">fontSize</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;0.9em&quot;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #006600; font-style: italic;">//eliminamos los mensajes antiguos que tuviese esa capa anteriormente</span>
   <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>msj.<span style="color: #660066;">hasChildNodes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #006600; font-style: italic;">//si tienes nodos hijos</span>
   <span style="color: #009900;">&#123;</span>
	  msj.<span style="color: #660066;">removeChild</span><span style="color: #009900;">&#40;</span>msj.<span style="color: #660066;">firstChild</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #006600; font-style: italic;">//creamos el nuevo</span>
   msj.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">createTextNode</span><span style="color: #009900;">&#40;</span>texto<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> crearCadenaConsulta <span style="color: #009900;">&#40;</span>deporte<span style="color: #339933;">,</span>color<span style="color: #339933;">,</span>correo<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
&nbsp;
 <span style="color: #003366; font-weight: bold;">var</span> cadenaConsulta<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
 cadenaConsulta<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;deporte=&quot;</span><span style="color: #339933;">+</span>deporte<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&amp;&quot;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;color=&quot;</span><span style="color: #339933;">+</span>color<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&amp;&quot;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;correo=&quot;</span><span style="color: #339933;">+</span>correo<span style="color: #339933;">;</span>
&nbsp;
&nbsp;
 <span style="color: #000066; font-weight: bold;">return</span> cadenaConsulta<span style="color: #339933;">;</span>  
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> chequeoCampos<span style="color: #009900;">&#40;</span>valordeporte<span style="color: #339933;">,</span>valorcolor<span style="color: #339933;">,</span>valorCorreo<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>   
&nbsp;
	<span style="color: #006600; font-style: italic;">//creamos un objeto de la clase formulario</span>
	<span style="color: #003366; font-weight: bold;">var</span> cadenaConsulta<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> registro<span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">new</span> formulario<span style="color: #009900;">&#40;</span>valordeporte<span style="color: #339933;">,</span>valorcolor<span style="color: #339933;">,</span>valorCorreo<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">//direccion de la url a donde va la peticion</span>
	<span style="color: #003366; font-weight: bold;">var</span> url<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">//validate se convierte en la propiedad de </span>
	registro.<span style="color: #660066;">validar</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #006600; font-style: italic;">//si el registro es valido pasamos a crear la cadena de consulta </span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>registro.<span style="color: #660066;">valido</span><span style="color: #339933;">==</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
	  cadenaConsulta<span style="color: #339933;">=</span>crearCadenaConsulta<span style="color: #009900;">&#40;</span>registro.<span style="color: #660066;">deporte</span><span style="color: #339933;">,</span>registro.<span style="color: #660066;">color</span><span style="color: #339933;">,</span>registro.<span style="color: #660066;">correo</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	  peticion<span style="color: #009900;">&#40;</span>cadenaConsulta<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> peticion <span style="color: #009900;">&#40;</span>cadenaConsulta<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>  
   <span style="color: #006600; font-style: italic;">//la direccion url donde ubicammos el fichero php</span>
   <span style="color: #003366; font-weight: bold;">var</span> url<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;respuesta.php&quot;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">XMLHttpRequest</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
&nbsp;
	 http_request<span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">new</span> XMLHttpRequest<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #000066; font-weight: bold;">else</span>
   <span style="color: #009900;">&#123;</span>
	  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">ActiveXObject</span><span style="color: #009900;">&#41;</span>
	  <span style="color: #009900;">&#123;</span>
&nbsp;
		  http_request<span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">new</span> ActiveXObject<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Microsoft.XMLHTTP&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>http_request<span style="color: #009900;">&#41;</span>
		  <span style="color: #009900;">&#123;</span>
			  http_request<span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">new</span> ActiveXObject<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Msxml2.XMLHTTP&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		  <span style="color: #009900;">&#125;</span>
	   <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
	<span style="color: #000066; font-weight: bold;">try</span>
	<span style="color: #009900;">&#123;</span>
	http_request.<span style="color: #660066;">onreadystatechange</span><span style="color: #339933;">=</span>muestraContenido<span style="color: #339933;">;</span>
	http_request.<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;POST&quot;</span><span style="color: #339933;">,</span>url<span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">//configuracion de la cabecera de una aplicacion post content type</span>
	http_request.<span style="color: #660066;">setRequestHeader</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Content-Type&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;application/x-www-form-urlencoded; charset=UTF-8&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	http_request.<span style="color: #660066;">send</span><span style="color: #009900;">&#40;</span>cadenaConsulta<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>err<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;espera unos segundo y vuelve a intentar conectar el servidor&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> 
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> muestraContenido <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>    
&nbsp;
	 <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>http_request.<span style="color: #660066;">readyState</span><span style="color: #339933;">==</span> <span style="color: #CC0000;">4</span> <span style="color: #009900;">&#41;</span>
	 <span style="color: #009900;">&#123;</span>  
	     <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;peticion completa&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		 <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>http_request.<span style="color: #000066;">status</span><span style="color: #339933;">==</span><span style="color: #CC0000;">200</span><span style="color: #009900;">&#41;</span>
		 <span style="color: #009900;">&#123;</span>   
			<span style="color: #003366; font-weight: bold;">var</span> respuesta<span style="color: #339933;">=</span>http_request.<span style="color: #660066;">responseText</span><span style="color: #339933;">;</span>
		    <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>respuesta<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #003366; font-weight: bold;">var</span> obj<span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">eval</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;(&quot;</span><span style="color: #339933;">+</span>respuesta<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;)&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			devolverDatos<span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		 <span style="color: #009900;">&#125;</span>
&nbsp;
	 	 <span style="color: #000066; font-weight: bold;">else</span>
	 	 <span style="color: #009900;">&#123;</span>
          <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;problema con la comunicacion con el servidor&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	 	 <span style="color: #009900;">&#125;</span>
	 <span style="color: #009900;">&#125;</span> 
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> devolverDatos <span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #006600; font-style: italic;">//mandamos los datos del servidor a la pagina del formulario a la capa de datos</span>
	<span style="color: #003366; font-weight: bold;">var</span> capaDatos<span style="color: #339933;">=</span>document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;datos&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">//creamos la cadena a mostrar</span>
&nbsp;
    <span style="color: #003366; font-weight: bold;">var</span> info<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;&lt;h4&gt; Los datos del proceso de inscripción son:&lt;h4&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	info<span style="color: #339933;">+=</span><span style="color: #3366CC;">&quot;&lt;br/&gt;deporte: &quot;</span><span style="color: #339933;">+</span>obj<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;deporte&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&lt;br/&gt;color: &quot;</span><span style="color: #339933;">+</span>obj<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;color&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&lt;br/&gt;correo: &quot;</span><span style="color: #339933;">+</span>obj<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;correo&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">//limpiamos si hay texto dinamico html</span>
&nbsp;
	capaDatos.<span style="color: #660066;">innerHTML</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">//damos formato</span>
&nbsp;
	capaDatos.<span style="color: #660066;">style</span>.<span style="color: #660066;">backgroundColor</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;#99CC00&quot;</span><span style="color: #339933;">;</span>
	capaDatos.<span style="color: #660066;">style</span>.<span style="color: #660066;">color</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;#FFFFFF&quot;</span><span style="color: #339933;">;</span>
	capaDatos.<span style="color: #660066;">style</span>.<span style="color: #660066;">width</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;80%&quot;</span><span style="color: #339933;">;</span>
	capaDatos.<span style="color: #660066;">style</span>.<span style="color: #660066;">border</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;thin solid black&quot;</span><span style="color: #339933;">;</span>
	capaDatos.<span style="color: #660066;">style</span>.<span style="color: #660066;">padding</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;0.5em&quot;</span><span style="color: #339933;">;</span>	
	capaDatos.<span style="color: #660066;">innerHTML</span><span style="color: #339933;">=</span>info<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> establecerEstilo <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
   <span style="color: #003366; font-weight: bold;">var</span> estilo<span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">value</span><span style="color: #339933;">;</span>
   <span style="color: #003366; font-weight: bold;">var</span> capaDatos<span style="color: #339933;">=</span>document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;datos&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
   <span style="color: #000066; font-weight: bold;">switch</span> <span style="color: #009900;">&#40;</span>estilo<span style="color: #009900;">&#41;</span> 
   <span style="color: #009900;">&#123;</span>
	  <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">'verde'</span><span style="color: #339933;">:</span>
	  capaDatos.<span style="color: #660066;">style</span>.<span style="color: #660066;">backgroundColor</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;#99CC00&quot;</span><span style="color: #339933;">;</span>
	  capaDatos.<span style="color: #660066;">style</span>.<span style="color: #660066;">color</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;#FFFFFF&quot;</span><span style="color: #339933;">;</span>
	  capaDatos.<span style="color: #660066;">style</span>.<span style="color: #660066;">width</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;80%&quot;</span><span style="color: #339933;">;</span>
	  capaDatos.<span style="color: #660066;">style</span>.<span style="color: #660066;">border</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;thin solid black&quot;</span><span style="color: #339933;">;</span>
	  capaDatos.<span style="color: #660066;">style</span>.<span style="color: #660066;">padding</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;0.5em&quot;</span><span style="color: #339933;">;</span>
	  <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	  <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">'azul'</span><span style="color: #339933;">:</span>
	  capaDatos.<span style="color: #660066;">style</span>.<span style="color: #660066;">backgroundColor</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;#0099FF&quot;</span><span style="color: #339933;">;</span>
	  capaDatos.<span style="color: #660066;">style</span>.<span style="color: #660066;">color</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;#FFFFFF&quot;</span><span style="color: #339933;">;</span>
	  capaDatos.<span style="color: #660066;">style</span>.<span style="color: #660066;">width</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;80%&quot;</span><span style="color: #339933;">;</span>
	  capaDatos.<span style="color: #660066;">style</span>.<span style="color: #660066;">border</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;thin solid red&quot;</span><span style="color: #339933;">;</span>
	  capaDatos.<span style="color: #660066;">style</span>.<span style="color: #660066;">padding</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;0.5em&quot;</span><span style="color: #339933;">;</span>
	  <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
&nbsp;
	  <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">'rosa'</span><span style="color: #339933;">:</span>
	  capaDatos.<span style="color: #660066;">style</span>.<span style="color: #660066;">backgroundColor</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;#FF33FF&quot;</span><span style="color: #339933;">;</span>
	  capaDatos.<span style="color: #660066;">style</span>.<span style="color: #660066;">color</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;#FFFFFF&quot;</span><span style="color: #339933;">;</span>
	  capaDatos.<span style="color: #660066;">style</span>.<span style="color: #660066;">width</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;80%&quot;</span><span style="color: #339933;">;</span>
	  capaDatos.<span style="color: #660066;">style</span>.<span style="color: #660066;">border</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;thin solid green&quot;</span><span style="color: #339933;">;</span>
	  capaDatos.<span style="color: #660066;">style</span>.<span style="color: #660066;">padding</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;0.5em&quot;</span><span style="color: #339933;">;</span>
	  <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
&nbsp;
	  <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">'cosmopolita'</span><span style="color: #339933;">:</span>
	  capaDatos.<span style="color: #660066;">style</span>.<span style="color: #660066;">backgroundColor</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;#6633CC&quot;</span><span style="color: #339933;">;</span>
	  capaDatos.<span style="color: #660066;">style</span>.<span style="color: #660066;">color</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;#FFFFFF&quot;</span><span style="color: #339933;">;</span>
	  capaDatos.<span style="color: #660066;">style</span>.<span style="color: #660066;">maxWidth</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;80%&quot;</span><span style="color: #339933;">;</span>
	  capaDatos.<span style="color: #660066;">style</span>.<span style="color: #660066;">border</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;thin solid yellow&quot;</span><span style="color: #339933;">;</span>
	  capaDatos.<span style="color: #660066;">style</span>.<span style="color: #660066;">padding</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;0.5em&quot;</span><span style="color: #339933;">;</span>
	  <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Enlace &#8220;link&#8221; a  siguiente post  <a href="http://www.railsymas.com/2009/07/14/ajax-y-php-3-parte/">Enlace Ajax  3 parte</a>  FINAL DEL EJEMPLO &#8220;finish&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.railsymas.com/2009/07/13/ajax-y-php-2-parte/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>lectura de ficheros en php</title>
		<link>http://www.railsymas.com/2009/06/16/lectura-de-ficheros-en-php-p/</link>
		<comments>http://www.railsymas.com/2009/06/16/lectura-de-ficheros-en-php-p/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 06:50:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.railsymas.com/?p=148</guid>
		<description><![CDATA[Php como muchos otros lenguajes permite la lectura de ficheros, con muchas similitudes a c++ Código de fichero lecturafichero.html este formulario se conecta a un script de php encargado de leer el fichero,. los name del formulario son las las variables que se van a pasar por método post al script de php para recogerlas [...]]]></description>
			<content:encoded><![CDATA[<p>Php como muchos otros lenguajes permite la lectura de ficheros, con muchas similitudes a c++</p>
<p>Código de fichero lecturafichero.html  este formulario se conecta a un script de php encargado de leer el fichero,. los name del formulario son las las variables que se van a pasar por método post al script de php para recogerlas<br />
mediante $_post['variable']</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
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #339933;">&lt;</span>style type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/css&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
  <span style="color: #339933;">.</span>formulario <span style="color: #009900;">&#123;</span> width<span style="color: #339933;">:</span>600px<span style="color: #339933;">;</span> margin<span style="color: #339933;">-</span>left<span style="color: #339933;">:</span>auto<span style="color: #339933;">;</span> margin<span style="color: #339933;">-</span>right<span style="color: #339933;">:</span>auto<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
  h1 <span style="color: #009900;">&#123;</span> text<span style="color: #339933;">-</span>align<span style="color: #339933;">:</span>center<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #339933;">.</span>botones <span style="color: #009900;">&#123;</span> margin<span style="color: #339933;">-</span>left<span style="color: #339933;">:</span>100px<span style="color: #339933;">;</span> margin<span style="color: #339933;">-</span>top<span style="color: #339933;">:</span>50px<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #339933;">&lt;/</span>style<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;formulario&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>h1<span style="color: #339933;">&gt;</span> Formulario Fichero <span style="color: #339933;">&lt;/</span>h1<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>form action<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;lecturafichero.php&quot;</span> method<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;post&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>label<span style="color: #339933;">&gt;</span>Nombre fichero Texto<span style="color: #339933;">&lt;/</span>label<span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;fichero&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&quot;</span> size<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;20&quot;</span> <span style="color: #339933;">/&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;botones&quot;</span><span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;submit&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;enviar&quot;</span><span style="color: #339933;">/&gt;</span>
&nbsp;
 <span style="color: #339933;">&amp;</span>nbsp<span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;reset&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;borrar&quot;</span> <span style="color: #339933;">/&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;/</span>form<span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p><span id="more-148"></span><br />
Código del fichero lecturafichero.php, se comprueba si el usuario del formulario ha introducido la dirección del fichero de texto a leer que puede ser un simple txt con alguna frase escrita, la instrucción encargada de comprobar esto es &#8220;isset&#8221; . </p>
<p>La comproboción de la existencia o no del fichero de texto a leer se hace mediante la instrucción file_exists.</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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&lt;style type=&quot;text/css&quot;&gt;
&nbsp;
  .centrado { width:800px; margin-left:auto; margin-right:auto; }
&nbsp;
&lt;/style&gt;
&lt;body&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
&nbsp;
   <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;div class='centrado'&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #666666; font-style: italic;">//si existe la variable de fichero </span>
&nbsp;
   <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;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'fichero'</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>
&nbsp;
   	  <span style="color: #666666; font-style: italic;">//llamamos a la funcion leer ficheros</span>
   	  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
   	  <span style="color: #009900;">&#123;</span>
   	   leerFicheros<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'fichero'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   	  <span style="color: #009900;">&#125;</span>
   	  <span style="color: #b1b100;">else</span>
   	  <span style="color: #009900;">&#123;</span>
   	  	 <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;a href='lecturafichero.html'&gt;no has introducido el fichero &lt;/a&gt;&quot;</span><span style="color: #339933;">;</span>
   	  <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #b1b100;">else</span>
   <span style="color: #009900;">&#123;</span>
   	 <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;a href='lecturafichero.html'&gt;no has introducido el fichero &lt;/a&gt;&quot;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
   <span style="color: #000000; font-weight: bold;">function</span> leerFicheros <span style="color: #009900;">&#40;</span><span style="color: #000088;">$fichero</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
   	 <span style="color: #000088;">$manejadorFichero</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fichero</span><span style="color: #339933;">,</span>r<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   	 <span style="color: #000088;">$numeroDelineas</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
   	 <span style="color: #666666; font-style: italic;">//bucle de lectura</span>
   	 <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">feof</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$manejadorFichero</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
   	 <span style="color: #009900;">&#123;</span>
   	 	<span style="color: #000088;">$numeroDelineas</span><span style="color: #339933;">++;</span>
&nbsp;
   	 	<span style="color: #000088;">$buffer</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fgets</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$manejadorFichero</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">4096</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   	 	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;linea <span style="color: #006699; font-weight: bold;">$numeroDelineas</span> , <span style="color: #006699; font-weight: bold;">$buffer</span> &lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
   	 <span style="color: #009900;">&#125;</span>
&nbsp;
   	 <span style="color: #666666; font-style: italic;">//terminamos de leer el fichero y lo cerramos</span>
   	 <span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$manejadorFichero</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/div&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;/body&gt;</pre></td></tr></table></div>

<p>Abrimos el fichero para lectura mediante fopen pasándole la dirección y el modo de lectura &#8220;r&#8221; obteniendo un manejador de fichero para el tratamiento del mismo. Mientras no sea fin de fichero &#8220;!feof&#8221; vamos leyendo con fgets las diferentes líneas de código.  </p>
<p>Si queremos cerrar el fichero mediante fclose(manejador de fichero ) liberamos los recursos y cerramos el fichero</p>
]]></content:encoded>
			<wfw:commentRss>http://www.railsymas.com/2009/06/16/lectura-de-ficheros-en-php-p/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

