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

Concatenation

I am trying to concatenate the first 3 variables into one WITH spaces. The test tells me I'm almost there, but am missing the spaces and can't seem to figure out how to add them. What gives?

Thanks for any help!

<?php

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



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

?>

2 Answers

Randy Hoyt
STAFF
Randy Hoyt
Treehouse Guest Teacher

Hey @Zach,

As you know, you can concatenate variables together like this:

echo $variable1 . $variable2;

You can also concatenate pieces of text together like this:

echo "ABC" . "DEF";

A space is just another piece of text, albeit a short one, that you could concatenate like this:

echo "ABC" . " " . "DEF";

You can concatenate pieces of text together with variables like this:

echo $variable1 . "ABC" . $variable2 . "DEF";

Does that help?

Fantastic! Bone-head move on my part.. was using the space at the end :)

Thanks for the quick reply, goes a long away for my sanity!