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

Abe Abdelmagid
Abe Abdelmagid
3,181 Points

not working

Fixing this code please

index.php
<?php

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

1 Answer

Bummer! syntax error, unexpected '"\n"' (T_CONSTANT_ENCAPSED_STRING) in index.php on line 7

Let's go investigate a String on line 7.

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

If you haven't already caught it, it is the fact you put 2 different strings side by side without concatenating them.

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

Or you could have made it 1 string.

$fullname = $fullname . ' was the original creator of PHP\n';

Task 2 wanted a space between firstName and lastName.

Task 3 they wanted you to print the sentence, not store it in a variable. By storing it in a variable you are negating the answer to task 2, cause it to fail.

<?php

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

Updated answer to reflect task 2 and 3. Sorry about that, didn't realize my mistake until I looked back at your question.

You're welcome. Vote my answer as 'best answer' if you thought it was helpful by clicking on the checkmark under my answer.