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

daniel Couzens
daniel Couzens
4,759 Points

Task 3 combining strings

What is wrong with this code?

index.php
<?php

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

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

?>

A few errors for you to correct to get this to work. I will not give you the answers directly, but will give you steps to complete the task.

  1. Your $fullName variable should be equal to your $firstName and $lastName variables concatanated together, with a space in between. DO NOT place your variable names within quotes.
<?php

$variable1 = 'PHP';
$variable2 = 'is easy';
$sentence = $variable1 . " " . $variable2 . ".\n" 

\\ Outputs:  PHP is easy.

?>
<?php

$firstName  = 'Rasmus';  
$lastName = 'Lerdorf';  
?>

Step 2 seems to be where you are struggling:

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

You need to create a 3rd variable $fullName (place it directly underneath the variables $firstName and $lastName).

// $fullName = $firstName and $lastName variables concatanted together with a space in between the words.

//Your final sentence should read:

<?php echo $fullName . " was the original creator of PHP. \n"; ?>

Notice how I have concatanated (joined together) the variable $fullName with the string " was the orginal creator of PHP. \n".

The variable and string are joined together using the dot or period.
Also notice that there is a space between the quote and the start of the string, otherwise i'd end up with:

Rasmus Lerdorfwas the original creator of PHP.

I hope this helps you work it out.

1 Answer

<?php

//Place your code below this comment - not working for some strang reason $firstName = "Rasmus"; $lastName = " Lerdorf "; $fullName = $firstName." ".$lastName;

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