FAQ: PHP Strings and Variables - String Concatenation

This community-built FAQ covers the “String Concatenation” exercise from the lesson “PHP Strings and Variables”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn PHP

FAQs on the exercise String Concatenation

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

Hi everyone!
I’m sort of got stuck. Either this or there is some error, as the topic is quite easy.
Task 3 about concatenating four strings "\n" , "tur" , "duck" , and "en"
I put the semicolon at the end. Used another \ before \n so that the system would perceive it as a string and of course added three points between them. The result ‘Did you print the four strings concatenated?’ Yep, definitely. I used different options: with additional spaces like this ’ ', with spaces before and after strings, without spaces, with commas between strings. So I would highly appreciate it if anyone could give me a hint about what I’m doing wrong?

Hi there, welcome to the forum.

Could we maybe see some code?
A link to the exercise would be helpful as well :wink:

Sure, no problem! Could have guessed) I’m just not a very ‘forum’ person )
echo "\n " . "tur " . "duck " . “en”;
https://www.codecademy.com/courses/learn-php/lessons/php-strings-and-variables/exercises/string-concatenation

Alright, I see

With what you’re doing, we’re printing this:

tur duck en

What we really want, though, is

turducken

Why could that be?


Edit: my bad, you did try that, didn’t you…


One thing I notice, while pasting your code, is this:

screen_php

If you’re also getting this, then it’s due to the quotes around en.

If you’re not getting that, then I’m not entirely sure.

Thank you.) That hepled ) I just misunderstood the task.
I thought, that I should have made \n to be perceived as a text and be printed together with other strings, hence I added another backslash. I got the result I wanted, but it wasn’t right )

The quotes around en were fine in the code. I guess it changed automatically, when I pasted it here.
But in the next codings I’ll be careful with quotes as well.
Thanks ))

Yeah then it’s probably just due to the forum formatting them that way.

Alright, glad you could solve this. Keep going!

I will! Thank you! :slightly_smiling_face:

hello
I am an aspirant for learning PHP language
I got a doubt
“why do we need to type “echo” every time we want a string of words or something like that??”

Hey there,

echo is a language construct, and was simply the chosen keyword for outputting things.

Other languages have print, printf, println, Console.WriteLine, DISPLAY, console.log, puts, fmt.Println, System.out.println, Write, say … among others.

ohk I got it but why isn’t it possible to write echo just one time then writing it everytime
like

<?php echo "i like codeacademy" "i like PHP" "i like echo"

Well, simply because PHP will not allow you to do that.

However, there are ways to do what you want to do using only one echo :slight_smile:

On one line, or multiple lines.

<?php echo "I like Codecademy" . " I like PHP " . "I like echo"; ?> <?php echo "I like Codecademy\n" . "I like PHP\n" . "I like echo"; ?> <?php echo " I like Codecademy I like PHP I like echo "; ?>

well !!!ohk
it means we have to connect them with dots
great!!!
THANKS A LOT!!!

Hi folks,

maybe it is a stupid Question, but ist “turducken” a madeup Word, or has it some meaning=?

What was the answer?

  1. Use echo to print a final portmanteau by concatenating these four strings "\n" , "tur" , "duck" , and "en" . Make sure to include a semicolon after the statement.

Link: https://www.codecademy.com/courses/learn-php/lessons/php-strings-and-variables/exercises/string-concatenation

What have you tried entering as a solution?

You can use </> for including code in posts.
For more details about preserving code formatting in forum posts, see: [How to] Format code in posts

I got it to work, thank you!

1 Like