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

PHP Basics String Manipulation issues

I'm trying to solve the 3 objectives, it says I'm not using the newline (\n) but I am.

I tested it in the workspace and it prints there as requested so either its not explained well enough OR its wrong.

index.php
<?php

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

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

$statement = " was the original creator of PHP\n";

echo $fullname . $statement;

?>

3 Answers

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

Hi there! Your code is functional, but you're doing something the challenge isn't expecting. You're introducing a new variable named $statement into your code. Keep in mind that challenges have very strict requirements and doing unexpected things can cause the challenge to fail even if otherwise functional. It's always a good idea when doing these challenges to try not to do anything that isn't explicitly asked for.

It wants you to concatenate $fullname and the string on the same line as your echo statement.

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

Hope this helps! :sparkles:

I really appreciate that response and so fast too! Yeah I was fully aware it was me going outside what it expected that was causing the issue it was just frustrating knowing that it produced the same result but didn't count!

I am having an issue with this too without introducing a new variable

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

I've tried this in my text editor and it works fine. What does the challenge want?

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

Hi there! As you are probably are aware, challenges are updated and changed slightly every so often. This challenge is one of those. And while your code will produce the same result, you are changing the original value of $fullName by concatenating.

On this line, the value of $fullName is "Rasmus Lerdorf":

$fullName=$firstName ." ". $lastName;

But on this line, the value of $fullName is "Rasmus Lerdorf was the original creator of PHP\n":

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

The challenge is wanting you to echo out the string without changing the original value of $fullName.

This is how I did it:

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

Going forward, it would probably be best to make a new question as opposed to tagging your question onto someone else's. There is no guarantee that anyone will see your question if it's not posted as a new question. Hope this helps! :sparkles:

Gotcha Thanks much! Wish they were more clear about what they want. I have a bit of coding experience but this can be really confusing for beginners.