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

PHP

Hi! I'm still stumped on a PHP question.

Here is the question:

Create a third variable named fullName that combines the $firstName and $lastName variables to make the string Rasmus Lerdorf.

Here is the code:

<?php

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

Could I please get the answer in code? I'm struggling with PHP and that would help.

Thanks!

index.php
<?php

//Place your code below this comment

?>

8 Answers

Amber Stevens
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Amber Stevens
Treehouse Project Reviewer

So what you're basically doing is combining the $firstName variable with the $lastName variable. The quotation marks with nothing but a space is done on purpose so that there's a space between the two names. Otherwise $fullname would look like this when it was printed out onto the page RasmusLerdorf when you actually want it to be Rasmus Lerdorf. PHP will automatically ignore whitespace unless you hardcode it in like that. Also I suggest you watch how your capitalizing your variable names it looks like both your variables are all lowercase letters when they should both have the second word capitalized ($firstName, as opposed to $firstname) I apologize because I realize I entered it wrong in my answer above. It should actually be $fullName = $firstName . " " . $lastName;

$fullName = $firstName + ' ' + $lastName;

Amber Stevens
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Amber Stevens
Treehouse Project Reviewer

You'd need to concatenate your $fullname variable using the dot like Alena shows in the videos. So: $fullname = $firstname . " " . $lastname;

I'm sorry, you guys, this is still not working. I'm confused about what goes where. For example: In $fullname = $firstname . " " . $lastname;

is there something that goes inside the two quotation marks? For some reason I'm really not understanding PHP.

Thank you very, VERY much for taking the time!! I may have one final question that I'll post in a couple minutes but we'll see if I can get it. :)

Can I ask one more question? I'm copying and pasting this from a different question I posted on the main part of this help site.

I am taking a quiz and I have no idea what to do. Here is the question:

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.

Here is my code:

<?php

//Place your code below this comment

$firstName = "Rasmus"; $lastName = "Lerdorf"; $fullName = $firstName . " " . $lastName "was the orignal creator of PHP";

?>

Would you mind helping me? Answers in code are best.

Thanks!

Your last answer worked for question #2. This is the third and final question of the quiz. THANK YOU!!

Amber Stevens
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Amber Stevens
Treehouse Project Reviewer

Looks like in the last part of your string you need to add another space so that there's space in between the last name and the rest of the sentence. As you have it right now it would print out "Rasmus Lerdorfwas the original creator of PHP". So instead of "was the original creator of PHP" try " was the original creator of PHP" (with a space between the quotation marks and the word was").