Foros del Web » Programando para Internet » PHP »

Ayuda con varios echo!

Estas en el tema de Ayuda con varios echo! en el foro de PHP en Foros del Web. Ayuda!!, lo uqe generalmente se hace es x ejemplo de un echo: Código PHP: <?php  $var  =  "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum." ; ?> Un echo normal seria: Código ...
  #1 (permalink)  
Antiguo 29/08/2010, 19:37
 
Fecha de Ingreso: febrero-2010
Mensajes: 56
Antigüedad: 14 años, 2 meses
Puntos: 1
Exclamación Ayuda con varios echo!

Ayuda!!, lo uqe generalmente se hace es x ejemplo de un echo:

Código PHP:
<?php 
$var 
"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
?>


Un echo normal
seria:
Código PHP:
<?php
echo $var;
?>
Pero deseo que sea llínea x linea:


Código PHP:
<?php
echo "Lorem Ipsum is simply dummy text of the printing and typesetting ";

echo 
" Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,";

Sabiendo que $var es pasada por un parametro $_POST
  #2 (permalink)  
Antiguo 29/08/2010, 19:54
Avatar de geq
geq
 
Fecha de Ingreso: agosto-2006
Ubicación: Rosario
Mensajes: 655
Antigüedad: 17 años, 8 meses
Puntos: 22
Respuesta: Ayuda con varios echo!

Hola,

Antes que nada, recuerda que seguramente tengas que recuperar las variables de $_POST y validarlas según lo que necesites. Algo simple:

Código PHP:
$var=$_POST['var']; 
Luego, ten en cuenta que no por poner dos echo verás dos líneas. Si quieres hacer un salto de línea deberás escribir \n. Si quieres que en la página web se vea un salto de línea deberás hacerlo con html, naturalmente con <br />.

Por último, cuando uses comillas dobles " " en el echo, podrás insertar las variables donde lo desees:

Código PHP:
echo "Lorem $var ipsum"
Distinto es si utilizas comillas simple ' '. En ese caso deberás cerrar la comilla y concatenar la variable.

Espero que te sirva, saludos!
  #3 (permalink)  
Antiguo 29/08/2010, 20:02
 
Fecha de Ingreso: febrero-2010
Mensajes: 56
Antigüedad: 14 años, 2 meses
Puntos: 1
Respuesta: Ayuda con varios echo!

Creo que no me entendiero :S.
Lo que nececito hacer es lo siguiente:
En cada línea de la variable haya una función x ejemplo:

$var = "Haciendo ping a google.com [72.14.253.104] con 32 bytes de datos:
Respuesta desde 72.14.253.104: bytes=32 tiempo=110ms TTL=250
Respuesta desde 72.14.253.104: bytes=32 tiempo=373ms TTL=250
Respuesta desde 72.14.253.104: bytes=32 tiempo=104ms TTL=250";

quede de la siguiente forma:

mostrar("Haciendo ping a google.com [72.14.253.104] con 32 bytes de datos:");
mostrar("Respuesta desde 72.14.253.104: bytes=32 tiempo=110ms TTL=250");
mostrar("Respuesta desde 72.14.253.104: bytes=32 tiempo=373ms TTL=250");
mostrar("Respuesta desde 72.14.253.104: bytes=32 tiempo=104ms TTL=250");
  #4 (permalink)  
Antiguo 29/08/2010, 20:02
 
Fecha de Ingreso: marzo-2010
Mensajes: 17
Antigüedad: 14 años
Puntos: 0
Respuesta: Ayuda con varios echo!

Ponle la etiqueta <br> haci saltara una linea.
Ejemplo:
Código PHP:
Ver original
  1. <?
  2. $var="Lorem Ipsum is simply dummy text of the printing and typesetting industry. <br>
  3. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, <br>
  4. when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting,<br>
  5. remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages,<br>
  6. and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
  7.  
  8. echo $var;
  9.  
  10. ?>
  #5 (permalink)  
Antiguo 29/08/2010, 20:05
 
Fecha de Ingreso: febrero-2010
Mensajes: 56
Antigüedad: 14 años, 2 meses
Puntos: 1
Respuesta: Ayuda con varios echo!

Cita:
Iniciado por IvanFoy Ver Mensaje
Ponle la etiqueta <br> haci saltara una linea.
Ejemplo:
Código PHP:
Ver original
  1. <?
  2. $var="Lorem Ipsum is simply dummy text of the printing and typesetting industry. <br>
  3. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, <br>
  4. when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting,<br>
  5. remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages,<br>
  6. and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
  7.  
  8. echo $var;
  9.  
  10. ?>




Noo!!; lo que nececito es de que x cada linea salga una funcion
  #6 (permalink)  
Antiguo 29/08/2010, 20:06
Avatar de geq
geq
 
Fecha de Ingreso: agosto-2006
Ubicación: Rosario
Mensajes: 655
Antigüedad: 17 años, 8 meses
Puntos: 22
Respuesta: Ayuda con varios echo!

Ahora te entendí, puedes separar un string con explode(). Eso te generará un array con cada parte del mismo.

Por ejemplo:

Código PHP:
$partes=explode("\n",$var);
mostrar($partes[0]);
mostrar($partes[1]);
mostrar($partes[2]);
mostrar($partes[3]); 
O, naturalmente, se podría hacer con un foreach para ahorrarte la repetición.

Saludos!
  #7 (permalink)  
Antiguo 29/08/2010, 20:19
 
Fecha de Ingreso: febrero-2010
Mensajes: 56
Antigüedad: 14 años, 2 meses
Puntos: 1
Respuesta: Ayuda con varios echo!

Cita:
Iniciado por geq Ver Mensaje
Ahora te entendí, puedes separar un string con [URL="http://php.net/manual/es/function.explode.php"]explode()[/URL]. Eso te generará un array con cada parte del mismo.

Por ejemplo:

Código PHP:
$partes=explode("\n",$var);
mostrar($partes[0]);
mostrar($partes[1]);
mostrar($partes[2]);
mostrar($partes[3]); 
O, naturalmente, se podría hacer con un foreach para ahorrarte la repetición.

Saludos!

Muchas gracias; si no es mucha molestia; ¿Cómo se3ria lo del foreach?
  #8 (permalink)  
Antiguo 29/08/2010, 20:24
Avatar de geq
geq
 
Fecha de Ingreso: agosto-2006
Ubicación: Rosario
Mensajes: 655
Antigüedad: 17 años, 8 meses
Puntos: 22
Respuesta: Ayuda con varios echo!

Código PHP:
$partes=explode("\n",$var);
foreach(
$partes as $parte) {
  
mostrar($parte);

El foreach recorre el array y en cada ciclo carga el $parte (la variable que está luego del "as") un elemento del mismo.

Saludos!
  #9 (permalink)  
Antiguo 29/08/2010, 20:26
 
Fecha de Ingreso: febrero-2010
Mensajes: 56
Antigüedad: 14 años, 2 meses
Puntos: 1
Respuesta: Ayuda con varios echo!

humm
lo malo esq no hay ningun \n en el exec (N)
  #10 (permalink)  
Antiguo 29/08/2010, 20:34
Avatar de geq
geq
 
Fecha de Ingreso: agosto-2006
Ubicación: Rosario
Mensajes: 655
Antigüedad: 17 años, 8 meses
Puntos: 22
Respuesta: Ayuda con varios echo!

Bueno, busca el caracter que los divide. Prueba con \r tambien, pero en eso está la clave.

Saludos!

Etiquetas: echo
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 00:04.