Im new to PHP and I can\'t figure out what the rules are for using the echo function. For example, if I need to echo a large block of css/js, do I need to add echo to each line
I prefer to concatenate multiple Strings together. This works either for echo AND for variables. Also some IDEs auto-initialize new lines if you hit enter. This Syntax also generate small output because there are much less whitespaces in the strings.
echo ''
.'one {'
.' color: red;'
.'}'
;
$foo = ''
.'' . $bar . '
' // insert value of bar
.$bar // insert value of bar again
."$bar
" // and again
."You can also use Double-Quoted \t Strings for single lines. \n To use Escape Sequences.
"
// also you can insert comments in middle, which aren't in the string.
.'Or to insert Escape Sequences in middle '."\n".' of a string
'
;
Normally i start with an empty string and then append bit by bit to it:
$foo = '';
$foo .= 'function sayHello()'
.' alert( "Hello" );'
."}\n";
$foo .= 'function sum( a , b )'
.'{'
.' return a + b ;'
."}\n";
(Please stop Posts like "uh. You answer to an five jears old Question." Why not? There are much people searching for an answer. And what's wrong to use five year old ideas? If they don't find "their" solution they would open a new Question. Then the first five answers are only "use the search function before you ask!" So. I give you another solution to solve problems like this.)