Page 1 of 1

Newline using single quotes

Posted: Thu Dec 11, 2008 5:39 pm
by socket1
I have some php code that wont return a newline when its between single quotes ex)

Code: Select all

 
$string1 = 'hello hello hello <br /> \n hello hello hello';
$string2 = "hello hello hello <br /> \n hello hello hello";
 
echo $string1;
echo '<br />';
echo $string2;
 


String1 does not work, it will not return a newline after the <br /> tag, string2 works fine.
I want to use all single quotes since a helpful person pointed out in a post before that using single quotes is better because when you use double quotes in your HTML inside a variable or such you do not have to put \ the escape character before all of them.

Re: Newline using single quotes

Posted: Thu Dec 11, 2008 6:02 pm
by Eran
New line characters (\n) can only be outputted inside double quotes. Just use concatenation for adding your linebreaks:

Code: Select all

$string = '<element attr="value"></element>' . "\n";