PHP PHP Basics Daily Exercise Program String Manipulation

Jeff Jones
Jeff Jones
1,546 Points

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
STAFF
Amber Stevens
Treehouse Staff

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;

Ray Thomas
Ray Thomas
10,813 Points

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

Amber Stevens
STAFF
Amber Stevens
Treehouse Staff

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

Jeff Jones
Jeff Jones
1,546 Points

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.

Jeff Jones
Jeff Jones
1,546 Points

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. :)

Jeff Jones
Jeff Jones
1,546 Points

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!

Jeff Jones
Jeff Jones
1,546 Points

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

Amber Stevens
STAFF
Amber Stevens
Treehouse Staff

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").