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 Daily Exercise Program String Manipulation

I need help with this String Manipulation challenge.

How do I complete this task? I've tried quite a few different techniques. Please help. Thank you

1) Use the $fullName variable

2) Display the following string to the screen: Rasmus Lerdorf was the original creator of PHP.

3) Use an escape character to add a newline to the end of the string.


//Place your code below this comment
$firstName = "Rasmus";
$lastName = "Lerdorf";
$fullName = $firstName + $lastName;

$myString = "$fullName" . ' was the original creator of PHP.' . "\n";
echo $myString;

1 Answer

Jennifer Nordell
Jennifer Nordell
Treehouse Teacher

Hi there! You're doing really well, but honestly, I'm not really sure why this passed the second step. The $fullName variable is supposed to contain the value "Rasmus Lerdorf". But because you've used the + sign between the $firstName and the $lastName this will cause PHP to treat that string as an integer and try to evaluate it as such. If the string cannot be converted to an integer, it will evaluate the entire thing as 0. When using var_dump($fullName); using your code, you will see that it var_dumps an int(0);

Remember, the concatenation operator is the . sign in PHP, which is what I feel fairly certain you meant to do here. That being said, if you use that here, you will still need to account for a space between the first name and the last name to get the proper output. My suggestion here is to use the double quotes to cause the strings to expand in place.

$fullName = "$firstName $lastName";

The rest of your code is fine except that, of course, the $fullName is now incorrect.

I'm going to tag Alena Holligan here because I feel like the challenge shouldn't have let you through the second step.

Hope this helps! :sparkles:

Alena Holligan
Alena Holligan
Treehouse Teacher

Thanks Jennifer Nordell :) fixed. It was the + which makes $fullName === 0

Wow, that makes a lot of sense!

I appreciate your help! I can now see what I was doing wrong.

Thank you!