This forum is now read-only. Please use our new forums! Go to forums
I wanna ask the differences
In this exercise, I can finish it with:
echo "<p>Hello! My name is " . $name . " and I am " . $age . " years old.";
however, I can also finish it with this:
echo "Hello! My name is $name and I am $age years old.";
Does the second one right? Or what’s the difference between them?
Answer 527d033e80ff33d04d003aa7
the first one is correct. remember php is a server side language unlike html. so if you run
“Hello! My name is $name and I am $age years old.”
in html that is how it will appear on the page. it will not access the php variables you may have created.
so in your first example you are using php to insert the variables into your html. the “.” is a concatenation string operator. you can append your variable to a string.
basically your first example is a far better practice to get into . the 2nd example may run in the editor but in a live environment it will cause you problems.
Answer 5278bca0f10c606b7f00c758
You can do both ways since both are correct but the first part would be preferrable when it comes to formatting your output. May I ask which part specifically are you referring to? Are you referring to the dots or the p tag?
1 comments
Yes, I’m curious about the dots and
. I had thought I must use them to arrange the string.
Popular free courses
- Free Course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner friendly,4 LessonsLanguage Fluency - Free Course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner friendly,11 LessonsLanguage Fluency - Free Course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner friendly,6 LessonsLanguage Fluency
2 comments
OK, got it, I will try the two in a server, to find the difference. Thank you!
go to here; http://writecodeonline.com/php/ insert your 2nd line into the editpr and see the result