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 trial

PHP

Juraj Ferenc
Juraj Ferenc
1,669 Points

php new line

Hello everyone I'm new into php and currently im taking PHP Basics course Well i encountered problem I dont know how to incorporate new line into for example my echos, i know that it was mentioned somewhere in course, but cant fin it. My basic code looks like

<html> <body> <?php $array_eyes = array( 'blue' , 'brown' , 'red'); print_r($array_eyes); //====Here i would like to have new line==== echo "Trying php with no success"; ?> </body> </html>

i tried to add <br> and \n like: print_r($array_eyes) "\n"; print_r($array_eyes) <br>;

but i always get error message. Any toughts please?

3 Answers

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

Hi there.

You've got the escape sequence right.

<?php
$array_eyes =  array( 'blue' , 'brown' , 'red');
print_r($array_eyes) . echo "\n";
//====Here i would like to have new line====
echo "Trying php with no success";
?>

What you want to do is concatenate your string that contains the escape character. So the next thing you echo to the screen will appear on a new line. :-).

Bryan Manhollan
PLUS
Bryan Manhollan
Courses Plus Student 9,666 Points

If its in HTML, you'll have to do a <br> instead of a \n. Just something to keep in mind as well.

Juraj Ferenc
Juraj Ferenc
1,669 Points

Hey guys Thank you for your comments Can you please add how to do it into my code? I know that in html i have to use <br> but i don't know how to put it there :)

Juraj Ferenc
Juraj Ferenc
1,669 Points

Strange is that this forum ignore <b r> :). Wrote it in my previous post and system didn't display it.