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

John Norris
John Norris
21,145 Points

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

John Norris
John Norris
21,145 Points

Wow, that makes a lot of sense!

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

Thank you!