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 trialJames Ackerman
14,099 PointsCan someone help with string concatenation?
I've tried a few different ways but can't seem to get it right. For example...
<?php
//Place your code below this comment
$firstName = 'Rasmus';
$lastName = 'Lerdorf';
$fullName = "$firstName " . "$lastName";
"$fullName was the original creator of PHP." . "\n";
?>
3 Answers
David Tomko
7,744 PointsYou need to add echo at the end.
echo "$fullName was the original creator of PHP." . "\n";
Pedro Oliveira
1,272 PointsHi, James Ackerman, everything fine?
To concatenate one string in PHP, we have several methods. I'll show you some of them:
$string = "String can have some $variables directly, but you will need always doublequote";
$string = "We can also ".$concatenate." some strings this way.";
$string = sprintf('Or even, we could %s and insert our values', 'use a function to let things more clear');
Remember that as pointed before, you will always need to echo
your string, otherwise, it will be just inside your code!
James Ackerman
14,099 Points@David That got it. I thought I had tried it with echo, but apparently I used echo with an incorrect submission. I ended up assuming I was adding something that wasn't being called for. Thanks much!
@Pedro Thanks for the additional information!