$var = \"Hi there\".\"
\".\"Welcome to my website\".\"
;\"
echo $var;
Is there an elegant way to handle line-breaks in PHP? I\'
Well, as with any language there are several ways to do it.
As previous answerers have mentioned, " is not a linebreak in the traditional sense, it's an HTML line break. I don't know of a built in PHP constant for this, but you can always define your own:
"
// Something like this, but call it whatever you like
const HTML_LINEBREAK = "
";
If you're outputting a bunch of lines (from an array of strings for example), you can use it this way:
// Output an array of strings
$myStrings = Array('Line1','Line2','Line3');
echo implode(HTML_LINEBREAK,$myStrings);
However, generally speaking I would say avoid hard coding HTML inside your PHP echo/print statements. If you can keep the HTML outside of the code, it makes things much more flexible and maintainable in the long run.