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

Ritual Zebra
Ritual Zebra
1,755 Points

PHP Becoming a comment in HTML

Hello! I recently started getting into PHP, and when I try to make the <?php echo $example ?>, for example all my HTML, CSS, and or PHP editors try to make it as a comment. Also when I inspect element with google chrome. Not sure why this happens but if somebody could help me that would be great!

Hey Logan can you post your code? use the markdown cheatsheet right above the "post answer" button to learn how to.

3 Answers

Tim Knight
Tim Knight
28,888 Points

Hi Logan,

You mentioned that all "editors" so I'm assuming you mean text editors you're editing your code with? If you're using Sublime Text or a similar editor are you using HTML syntax or PHP syntax in the editor? And just to confirm, and I apologize if this has been addressed in the comments above, but you are running this through a PHP server correct? Just loading the file in your browser will not produce the expected result. You'll need something like MAMP, WAMP, or something similar to get you going.

Scott Evans
Scott Evans
4,236 Points

This seems like whats going on to me also.

you're right, that must be the problem, not running local server

There seems to be a syntax error on line 18 on the meta tag missing the double quotes, see below:

<meta charset="UTF-8">

See if that makes a difference

Also your missing closing semi-colons after your echo function

      <h1><?php echo $name; ?></h1>
      <p><?php echo $location; ?></p>

Did you save your file with .php extension?

Try and remove all instances of PHP, and slowly add them back, start by removing your constants and variables and echo a string with your name instead of the variable, like this:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Treehouse Profile</title>
    <link href="css/style.css" rel="stylesheet" />
  </head>

  <body>
    <section class="sidebar text-center">
      <div class="avatar">
        <img src="img/avatar.png" alt="">
      </div>
      <h1><?php echo 'Logan'; ?></h1>
      <p><?php echo 'Somewhere'; ?></p>
      <hr />
      <p>Welcome to PHP Basics!</p>
      <hr />
      <ul class="social">
        <li><a href=""><span class="icon twitter"></span></a></li>
      </ul>
    </section>
    <section class="main">
      <pre>

      </pre>
    </section>
  </body>
</html>

if it works then start adding back the rest of your code.

Good luck!