Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialS.M.Mohieminul Hossain
3,329 PointsPHP new line
As Hampton shows in this video that "\n" makes a new line in php but it is not working on my PC.As far i understand \n creates a newline in the source code.So what is the best way to make a new line in php?
S.M.Mohieminul Hossain
3,329 Pointsyes.. local server is running on my PC
Sean Do
11,933 PointsCan you copy & paste source?
S.M.Mohieminul Hossain
3,329 Points<?php
echo "<h1>Hello php </h1>";
$greeting = "Hello Everyone!\n";
$greeting_ask = "How are you?";
echo $greeting; echo $greeting_ask;
?>
Andrey Filenko
234 PointsTry using \r\n instead of \n
3 Answers
Mike Costa
Courses Plus Student 26,362 Points\n does make a new line but if you're echoing your output to a website, you should use a break tag <br> instead.
Ted Sumner
Courses Plus Student 17,967 PointsTry putting a space before the \n.
melk
24,762 PointsI had the same problem and learned to use PHP's newline to break function.
Example:
echo nl2br("foo isn't\n bar");
See the site http://php.net/manual/en/function.nl2br.php
Also, the \n will work correctly within the confines of the HTML "pre" tags.
Sean Do
11,933 PointsSean Do
11,933 PointsIs your local server on your PC running? PHP can't run standalone like HTML/CSS/JS.