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

Diego Osorio
Diego Osorio
5,198 Points

I dont understand why this code is wrong for the challenge

<?php

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

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

echo("$sentence"); ?>

index.php
<?php

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

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

echo("$sentence");
?>

2 Answers

Hi guys,

You can actually use variables inside double quotes and they are still going to return their values. It actually doesn't if you put it inside single quotes.

Diego's line of code is fine, you just need to take the dot after $fullname off, and the space between PHP and the \n. Alexander is right about the echo with no parenthesis. And you don''t need to create a new $sentence variable. Just echo it right away. Try the line bellow..

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

Remember, the big issue here is that there shouldn't be an space between PHP and \n.

You can also try this:

$fullname = "$firstName $lastName";

Watch this video about escape sequences: https://teamtreehouse.com/library/escape-sequence

Cool! I'm new to PHP, and I didn't know that.

Diego Osorio
Diego Osorio
5,198 Points

Thank you Filipe ! well explained.

Don't use double quotes around variables. If you don't, your code should work. Also, there's no need for parentheses when using the echo function (although you still could use parentheses if you'd like). Try this:

<?php

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

$fullname = $firstName . " " . $lastName;

// Over here, you used $fullname inside of double quotes again!
//$sentence = "$fullname. was the original creator of PHP \n";

// That line of code above this comment wouldn't pass this challenge...
// Instead, try this! I combined whatever is in the fullname variable and connected it to the
// string. :) This should fix it!
$sentence = $fullname . "was the original creator of PHP \n";


// See how I got rid of the parentheses (you don't need to, to me it just looks cleaner) and how
// I got rid of the double quotes (very important! If you used double quotes around a variable it
// won't get the value of the variable.)? That should fix it :)
echo $sentence;

?>

Hope it helps! ~Alex :smile:

Diego Osorio
Diego Osorio
5,198 Points

Thank you for your help alex! also you are right about the use of the parentheses.