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) What is PHP? Intro to Workspaces and PHP Code

Jeffrey Cheong
Jeffrey Cheong
5,653 Points

Problems adding the "Hello World" to the browser.

I am adding <p><?php echo "Hello, World!" ?></p> to the section tag and it does not show on the preview page. It shows when inspect the element as just

<p><?php echo "Hello, World!" ?></p>

instead of

<p>Hello World!</p>

Is it just a problem with the workspace or am I doing something wrong?

Jeffrey Cheong
Jeffrey Cheong
5,653 Points

Sorry, when I inspect the element it shows <!--?php "Hello World" ?-->.

6 Answers

Roy Penrod
Roy Penrod
19,810 Points

What does your code look like?

We really need to see it to be able to tell what's going wrong.

Jeffrey Cheong
Jeffrey Cheong
5,653 Points

thats strange, I tried adding "<p><?php echo "Hello, World!" ?></p>" to the comment (without the "") and it didn't work.

Roy Penrod
Roy Penrod
19,810 Points

Hey, Jeffrey ... you couldn't post the code because you were using single quotes. What you need to use is the back quote key. Most keyboards have it just to the left of the number 1.

I did the same thing the first time I tried to post a code sample.

Roy Penrod
Roy Penrod
19,810 Points

Based on what you typed, it looks like you forgot the opening php tag. Here's what it should look like:

<p><?php echo "Hello World"; ?></p>
Jeffrey Cheong
Jeffrey Cheong
5,653 Points

Sorry but the code is not showing, maybe this will work: "paragraph tag"<?php echo "Hello, World!" ?>"/paragraph tag"

Jeffrey Cheong
Jeffrey Cheong
5,653 Points

Yeah that's what I have in my html workspace, and it's not showing in the preview and when I inspect the element it just looks like what is above except in place of the paragraph tags there are comment tags.

Roy Penrod
Roy Penrod
19,810 Points

Sounds like you've got a comment tag surrounding it somewhere in your source code.

Look for these tags and remove them if they're around the php statement:

<!--     <-- remove that tag
-->     <-- remove that tag
Jeffrey Cheong
Jeffrey Cheong
5,653 Points

Hey Roy thanks for the help but it was just a minor error that I missed, apparently I had to change the index.html to index.php but workspace started it up in index.html I don't know why.

Jeffrey Cheong
Jeffrey Cheong
5,653 Points

I don't have the comment tags in my source code this is what I have in that section tag exactly and it doesn't seem to work.

 <section class="main">
      <p>Let's Get Started!</p>
     <p><?php echo "Hello World"; ?></p>
    </section>
Roy Penrod
Roy Penrod
19,810 Points

Ah, I see. Yep, the .php extension will do it. Glad you figure it out.