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

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!