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
Harry James
14,780 PointsSplitting two strings on two lines
Hello,
I am new to PHP and am learning it for a school project. I was wondering, how do I go about splitting two strings onto two lines?
I have tried echoing both strings but, they just merge together on the webpage.
Is it possible to split one onto the line below?
E.G:
$string1 = "Hello, I am a string";
$string2 = "How are you today?";
echo $string1, $string2;
// Returns ==> Hello, I am a stringHow are you today?
// But can you make it return this:
// Hello, I am a string
// How are you today?
// (Split onto two lines).
Thanks in advance!
1 Answer
Jeremy Hayden
1,740 PointsYou can add \r\n to the end of your first line. or <br> works too.
or change your echo statement to:
echo $string1 . "<br>" . $string2;
Harry James
14,780 PointsHarry James
14,780 PointsThanks! I couldn't quite get the first one to work but the change for the echo statement worked perfectly!
Appreciate the help!