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

Deleted User

Concatenation Challenge question #3

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

What is wrong with this concatenation of text and the variable I created?

6 Answers

Deleted User

I think your quotation marks only need to be around the text eg: "The designer at Shirts 4 Mike shirts is named" . $fullName;

James Barnett
James Barnett
39,199 Points

Inside double quotes you don't need concatenation.

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

If you want to make your life hard you can do:

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

See for yourself, with this micro-demo I made for you

Deleted User

Thank you James. That was very helpful. I dont recall that point being made in the video.

Randy Hoyt
STAFF
Randy Hoyt
Treehouse Guest Teacher

Hey @Jason,

I just covered that second form in the video. (I haven't explained the difference between using single quotes and double quotes around pieces of text yet, so I wanted to use a syntax that would work with both of them. :-)

I trust you were able to get through the code challenge?

I can't get it. I've done almost every combo I could think of.

. <pre><?php

$firstName = "Mike"; $middleName = "the"; $lastName = "Frog"; $fullName = ""; $fullName = $fullName . $firstName . " "; $fullName = $fullName . $middleName . " "; $fullName = $fullName . $lastName;

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

?></pre>

Randy Hoyt
Randy Hoyt
Treehouse Guest Teacher

Hmmm ... I think it is not recognizing the &nbsp;. I think it should work if you just press the spacebar to type a plain space:

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

Does that help?

Yes, that worked! I tried everything I could think of. I even did .' '; But I guess I needed double quotes not single. Sheesh! Thanks so much!

James Barnett
James Barnett
39,199 Points

The important lesson here is that double quotes work with variable replacement whereas single quotes treat all characters as literals.