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 PHP Basics (Retired) PHP Conditionals & Loops Conditionals

Simon Strömberg
Simon Strömberg
1,423 Points

make space in php between two elements

if( USE_FULL_NAME == TRUE ) { $name = $first_name . '' . $last_name;

I cant figure out how to make the space between $first_name and $last_name, couldnt see what letters he typed in the video.

Now im using this: . '' .

But doesnt make a space

3 Answers

Peter Kullmann
Peter Kullmann
14,267 Points

You are pretty close to concatenating the variables and the space correctly.

In PHP, you use the period (.) for combining several strings and values of variables. With three variables, it looks like this:

var $text1 = "Hello ";
var $space = " ";
var $text2 = "World";
echo $text1 . $space .  $text2

The result will be "Hello world". Now that you want to echo a string in between two variables, you have to surround the string in quotation marks (either " like in my example or ' like in your code) just like in the following example:

var $text1 = "Hello ";
var $text2 = "World";
echo $text1 . " " .  $text2

This way we get the same result without using a variable for the space.

If you are not sure what exactly is typed in the video, you can always download the project files and find the corresponding code there.

Simon Strömberg
Simon Strömberg
1,423 Points

Hello, there is no files to download in this course..

var $text1 = "Hello "; var $space = " "; var $text2 = "World"; echo $text1 . $space . $text2

If i wanna do this on 1 row? How would i write it if you use my code?

Regards

Peter Kullmann
Peter Kullmann
14,267 Points

I just realized there is no project files to download for that course, sorry about that. You can still follow along by launching a Workspace.

If you decide to use single quotation marks (') instead of the double ones ("), the second example will look like this:

var $text1 = 'Hello ';
var $text2 = 'World';
echo $text1 . ' ' .  $text2

Beware that there still needs to be a space between the quotation marks.

Simon Strömberg
Simon Strömberg
1,423 Points

Thank you, it was the space i missed between the quotes.

Clint Rhea
Clint Rhea
2,354 Points

We have to think of a space it as it's own character (technically it is) - no different than a letter or number.