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 have a problem with my challenge on concatenating strings..

Use the $fullname variable to display the following string to the screen. Use an escape character to add a newline to the end of the string. 'Rasmus Lerdorf was the original creator of PHP'

index.php
<?php

//Place your code below this comment
$firstName = 'Rasmus';
$lastName = 'Lerdorf';

//$fullname = $firstName .' '. $lastName;
$fullname = "'" . $firstName .' '. $lastName . ' was the original creator of PHP\'' . "\n";
echo $fullname;

?>

2 Answers

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

Hi there! You're really close. What if I added this little tidbit to the instructions: "without changing the previous value of $fullname"? The problem here is that you're changing the value of $fullname from what passed in step 2.

Try echoing your new string directly with something like echo "My uncle is named $fullname";

Hope this helps, but let me know if you're still stuck! :sparkles:

Thanks but i am still stuck, system keeps telling me "Oops! It looks like Task 2 is no longer passing."

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

Well here we go then! The two main problems here are that you are

  1. overthinking this
  2. you are overwriting the previous value of $fullname

Take a look:

<?php

//Place your code below this comment
$firstName = 'Rasmus';
$lastName = 'Lerdorf';

//$fullname = $firstName .' '. $lastName;
$fullname = $firstName .' '. $lastName;
echo "$fullname was the original creator of PHP\n";

?>

Here you can see that I left the $fullname variable set to the full name of Rasmus Lerdorf. You were changing $fullname to be equal to "Rasmus Lerdorf was the original creator of PHP.\n". And his full name isn't that long! It sounds mildly like the Artist formerly Known as Prince :smiley:

Then we echo out the $fullname and the string given by the challenge instructions. We do this directly in the echo so as not to replace the original value of $fullname. Hope that clarifies things! :sparkles:

Thank you very much, it worked... very grateful. Now i can move on..

I think you are taking the instructions too literally. Try:

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

In other words, no single quotes. By the way, this works too:

$fullname = "$firstName $lastName was the original creator of PHP\n";
echo $fullname;
Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Unfortunately, this code will also not pass the challenge as it overwrites the original value of $fullname as indicated in my answer above. The original value of $fullname must be left intact and unaltered for the challenge to pass :smiley: