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 (Retired) PHP Data & Structure PHP Variables

Why are we preserving the quotation marks around the alt name of the image of Mike the Frog? & What does echo mean?

Hi all, Taking the PHP intro with Hampton, and I noticed that he changed the formerly HTML document from this:

<section class = ''>
<div class = ''>
<img src = "img/avatar.png" alt = "Mike the Frog">

To this:

<section class = ''>
<div class = ''>
<img src = "img/avatar.png" alt = "<?php echo $name ?>">

But why are we preserving the quotation marks around the variable in the alt? Isn't that redundant because in the variable assignment there's quotation marks around the name of "Mike"?

Also on a separate note, I didn't feel like Hampton really explained what echo is...is it simply let's return whatever value we assign the variable to be? It seems like the server does some HTML conversion though...like when he looks at the console the full PHP code isn't present...so what's happening?

Thanks for your help!

1 Answer

Vince Brown
Vince Brown
16,249 Points

Hey Abby, To answer your question let's start with the variable assignment.

in php there are 7 data types, which means ways we can store our data in variables. These are



Float (floating point numbers - also called double)





When you want to store a value like a name for an alt tag you would use the string Data type which to the computer just means a sequence of characters.

To set a variable in php that holds string data we need to wrap it in quotations.


$name = "Mike the Frog";


These quotations are not actually apart of the variable , so whenever you use the variable your output will be

Mike the Frog


"Mike the Frog"

The echo function outputs a string so when you use it with the $name variable your result would be


$name = "Mike the Frog";

// call echo
echo $name;

// the output would be
Mike the Frog


Since the Quotation marks are not apart of our output that is why you must retain them in your markup. If you left them off your markup would not output correctly

// without the quotation marks the code below 

<img src="img/avatar.png" alt=<?php echo $name ?>>

// would output

<img src="img/avatar.png" alt=Mike the Frog>

// which is not valid so we retain the quotation marks

<img src="img/avatar.png" alt="<?php echo $name ?>">

// and the output is valid markup

<img src="img/avatar.png" alt="Mike the Frog">

I appreciate the time you took to really flesh out this answer. Thanks!