This is the code inside my PHP loop:
echo 'Name: ' . $name . '<br/>';
How do I cause the PHP to begin a new HTML line with each iteration of the loop (instead of printing everything on a single HTML line)?
You need to include newline characters in your output. Thus:
echo 'Name: ' . $name . "<br/>\n";
Note the double quotes, which are necessary for the escaped \n to appear as a newline character instead of a literal \n.
Another useful escape is \t, which inserts tabs into your output.
Lastly, as an unrelated tip, it is faster to pass multiple strings to echo
with commas instead of periods, like so:
echo 'Name: ', $name ,"<br/>\n";
This is because using the dot causes PHP to allocate a new string buffer, copy all of the separate strings into that buffer, and then output this combined string; whereas the comma causes PHP to simply output the strings one after another.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With