Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP Build a Simple PHP Application Adding a Contact Form Concatentation

Rather stuck on this question

Would any one be able to help me with this question , dont think im quite understanding

Create a variable called fullName and assign it a value equal to the concatenation of the firstName variable, a space, the middleName variable, a space, and the lastName variable.

11 Answers

Keith Kelly's answer(s) are awesome and helped you through your issue beautifully. Couldn't help but see that it looks like where your understanding got foggy was with concatenation. In this instance, think of Concatenation like you would adding words together to make a sentence. The "plus"operator in PHP is "." but in english that is the equivalent as an adding operator. That's all concatenation is! So if you think about building the sentence "The sky is a hue of blue!", if you were to build that with concatenation it could look something like this:

<?php
echo "The" . " "  . "sky" . " " . "is" . " " .  "a" . " " . "hue". " " . "of" . " " . "blue" . "!"
// The sky is a hue blue!

With variables you can change a value, so you could end up with something like:

<?php
$color = "red";
echo "The" . " "  . "sky" . " " . "is" . " " .  "a" . " " . "hue". " " . "of" . " " . $color  . "!"
// The sky is a hue red!

$color = "green";
echo "The" . " "  . "sky" . " " . "is" . " " .  "a" . " " . "hue". " " . "of" . " " . $color  . "!"
// The sky is a hue green!

$color = "burple";
echo "The" . " "  . "sky" . " " . "is" . " " .  "a" . " " . "hue". " " . "of" . " " . $color  . "!"
// The sky is a hue burple!

Hope this helps a bit

Keith Kelly
Keith Kelly
21,326 Points

Basically it would look something like this:

$fullName = $firstName . ' ' . $middleName . ' ' . $lastName;

In that case you are combining or concatenating all of the individual name variables to create a full name.

ok so by adding \n in there wouldnt vaildate

Keith Kelly
Keith Kelly
21,326 Points

Are you attempting to add the new line break to the end of the variable? I wouldn't put it in the variable itself, but in the echo command when you call the fullName variable.

im a little lost here and may need to research a little more , like "Use concatenation to add an exclamation point to the echo command after the fullName variable." this questions just stumps me

Keith Kelly
Keith Kelly
21,326 Points

Whenever you are concatenating you are simply combining bits of information into a single piece. For example in the above comment you would echo the following.

echo $fullName . '!';

So what is happening is that php will echo the full name of the person (first middle last) then using the period you are telling php to add the exclamation point after the name. So it would look like:

Keith Bryan Kelly!

Hope this helps.

ahhhhh it makes sense now !! Thanks Keith

Keith i added it the way you said and it was wrong "echo "The designer at Shirts 4 Mike shirts is named $fullName . '!'"; any ideas?

Keith Kelly
Keith Kelly
21,326 Points

OK, so you need to have "The designer at Shirts 4 Mike is" before the full name. It will be the same concept. You will echo the first statement then add a period to concatenate the $fullName variable and then concatenate the exclamation point. It would look like this:

echo 'The designer at Shirts 4 Mike is ' . $fullName . '!';

Make sure that you have a space after the word "is" before you close the quotes so that it is separated from the full name.

Let me know if this works for you.

Nope is not having any of it, If i use your version it says that code three isnt working and if i do it like : echo "The designer at Shirts 4 Mike shirts is named" $fullName .'!'.; it pulls any error

Keith Kelly
Keith Kelly
21,326 Points

It looks like you have an extra period after the exclamation point. It is probably throwing the error because it is expecting another value to concatenate. Try removing that period.

PHP Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in concatenation.php on line 9 PHP Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in concatenation.php on line 9 thats the php error

echo "The designer at Shirts 4 Mike shirts is named" $fullName .'!'; like this?? it dosnt work

Keith Kelly
Keith Kelly
21,326 Points

You are also missing the period between the "named" and $fullName. It should look like this:

echo "The designer at Shirts 4 Mike shirts is named " . $fullName . "!";

Spot on ! Works thank you

Thank you Riley That helped so much! Im sure i will get there soon! But its coming together!!