gregs
February 28, 2011, 11:11am
1
if ($error != '') {
echo '<div id="error">'.$error.'</div>'."\
";
}
if ($error != '') {
echo "<div id=\\"error\\">".$error."</div>\
";
}
I have seen the above done a few ways. Both work as intended, but is there any “Set in stone” way of using
?
It seems just because code works, doesn’t mean it is always the best way.
Is there a better way of adding
at the end of a sentence in order to make the output source correct and easier to read?
TimIgoe
February 28, 2011, 11:16am
2
To ‘parse’ code in strings (
) you have to put it in double quotes ("), there is certainly no right or wrong way to do this, its down to personal preference.
I tend to go for the mixing and matching quotes myself, but i rarely print
etc at all.
Immerse
February 28, 2011, 11:17am
3
I don’t think there’s one particular way that is better than the other. Go with what you feel comfortable with.
One more option:
if ($error != '') {
echo '<div id="error">'.$error.'</div>' . chr(10);
}
gregs
February 28, 2011, 11:38am
4
This is the type of coding I like. It is clean and precise without jumping in and out of quotes/apostophes.
Is chr(10) safe to use in that way? Will it have adverse effects on different browsers or shortfalls in the future?
Immerse
February 28, 2011, 2:33pm
5
It can’t imagine it will, chr(10) just means a new-line character. As far as I know, it’s identical to "
"
gregs
February 28, 2011, 2:44pm
6
Thanks for all the replies!
TimIgoe
February 28, 2011, 2:45pm
7
chr(10) is a “line feed” (
)
chr(13) is a “carriage return” (\r)