/n and new lines problem...

A

Anonymous

Guest
Hello,

I'm learning PHP (I'm a very newbie :) and I'm testing PHP code from my tutorial. Next code should write the text strings in several lines, but it only writes one line... Why??

Code:
<p>
<?php
echo "First line \n Second \n Third \n";
echo "another \n and other";
$texte2 ="1st line \n 2nd line";
echo "$texte2"
?>

or for example:

Code:
<?php
/* Asignando una cadena. */
$str = "Esto es una cadena";
/* Añadiendo a la cadena. */
$str = $str . " con algo más de texto";
/* Otra forma de añadir, incluye un carácter de nueva línea protegido. */
$str .= " Y un carácter de nueva línea al final.\n";
echo "$str";
echo "berberecho";

Thanks,

Joan
 
Code:
<?
/* Asignando una cadena. */ 
$str = "Esto es una cadena"; 
/* Añadiendo a la cadena. */ 
$str = $str . " con algo más de texto"; 
/* Otra forma de añadir, incluye un carácter de nueva línea protegido. */ 
$str .= " Y un carácter de nueva línea al final.\n"; 
echo "$str"; 
echo "berberecho"; 
?>

i saw here just 1 "\n" =)

Code:
$str = $str . " con algo más de texto";

this action not for adding new lines =)
 
Pejone said:
Code:
<?
/* Asignando una cadena. */ 
$str = "Esto es una cadena"; 
/* Añadiendo a la cadena. */ 
$str = $str . " con algo más de texto"; 
/* Otra forma de añadir, incluye un carácter de nueva línea protegido. */ 
$str .= " Y un carácter de nueva línea al final.\n"; 
echo "$str"; 
echo "berberecho"; 
?>

i saw here just 1 "\n" =)

and???

Code:
$str = $str . " con algo más de texto";

this action not for adding new lines =)

Yes, but and the other /n (there are a lot)?

By way, I've discobered that if I put a <br> then break line happens...

Code:
<p>
<?php
echo "First line <br> Second <br> Third \n";  //pay attention to the <br> tags, in my first missage there are /n...
echo "another \n and other";
$texte2 ="1st line \n 2nd line";
echo "$texte2"
?>
[code]

But why /n doesn't run??

Regards,

Joan
 
<br> for html-coding - new line only in brouser
\n - new lines in generated file

Code:
<?
echo "<pre>";
echo "First \n Second \n Third \n";
?>
 
Back
Top