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

ZoDo .
ZoDo .
13,135 Points

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

I have try this code on workspace and seems to work just fine....but still i have errors on the test. any suggestion?

<?php

//Place your code below this comment $firstName = 'Rasmus'; $lastName = 'Lerdorf'; $fullName = "$firstName " . "$lastName "; $fullName .= 'was the original creator of PHP. '; $fullName .= "\n"; echo $fullName ?>

index.php
<?php
//Place your code below this comment
$firstName  = 'Rasmus';
$lastName   = 'Lerdorf';
$fullName   = "$firstName " . "$lastName ";
$fullName  .= 'was the original creator of PHP. ';
$fullName  .= "\n";
echo $fullName

?>

7 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! You're doing great. What if I added this additional instruction? Echo out the final string without changing the value of $fullName. Every time you are concatenating onto the end of the $fullName variable thus changing its value. At the end of this, your $fullName will hold "Rasmus Lerdorf was the original creator of PHP.\n". But $fullName should only ever contain "Rasmus Lerdorf".

Take this example:

$myName = "Jennifer";
echo "My name is $myName";

In this example, I use the value inside $myName and expand it directly in the string I'm echoing out without changing its original value.

I think you can get it with these hints, but let me know if you're still stuck! :sparkles:

Jon Tolentino
Jon Tolentino
5,332 Points

Hope this Help Bro!!

$firstName = 'Rasmus'; $lastName = 'Lerdorf'; $fullName = $firstName . ' ' . $lastName; echo "$fullName was the original creator of PHP \n";

ZoDo .
ZoDo .
13,135 Points

Hi, Jennifer, thank you a lot I have copied your code but it still does not work, seems this challenge has something personal with me :)

it works just add a period to jennifer's code

ZoDo .
ZoDo .
13,135 Points

Hi Jennifer, well i think i figure it our bu it seems to give me still an error Here is my code:

<?php
//Place your code below this comment
$firstName  = 'Rasmus';
$lastName   = 'Lerdorf';
$fullName   = "$firstName " . "$lastName";
echo "$fullName was the original creator of PHP \n";

?>

Thank You.

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! You did get it! Except for some reason, it really doesn't want you to have a space between the new line. So if IO change it to this, it passes:

echo "$fullName was the original creator of PHP\n";

Hope this helps! :sparkles:

Zachary Scott
Zachary Scott
1,648 Points

I found this to work well:

<?php
$firstName = "Rasmus";
$lastName = "Lerdorf";
//Create a third variable named fullName that combines the $firstName and $lastName variables to make the string Rasmus Lerdorf.
$fullName = $firstName . " " . $lastName;
// 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.
echo $fullName . " " . " was the original creator of PHP. \n";
?>
echo "$fullName was the original creator of PHP.\n";
<?php

//Place your code below this comment
$firstName = "Rasmus";
$lastName = "Lerdorf";
$fullName = $firstName." ".$lastName;
echo $fullName. " was the original creator of PHP.\n";
?>