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

Php tags are not turning pink and when viewing site it is just a blank page. I've changed it to index.php still no use

Anyone else having this problem? I've changed from .html to .php but the tags dont seem to work, get a blank page when viewing the site. If i take php tags out the site goes back to normal....

3 Answers

Zach Elkins
Zach Elkins
9,602 Points

As Mark said above, PHP can be run in workspaces without any issue, as long as it is named properly as a .php file. However, ending up with a blank page can be caused by something as simple as not closing a statement or forgetting an '=' when naming a variable.

For example: <?php $name = "Mike"; ?>

works perfectly fine in the code, but this:

<?php $name "Mike"; ?>

breaks the page, resulting in a blank page. The difference can many times be as simple as a forgotten = or ;

Hope this helps.

Are you running it on your local machine? PHP needs to run through Apache. There are videos that instruct you on how to download and use MAMP or XAMP here so you can run PHP locally. I believe they are in some of the first PHP lessons.

I'm running it through the workspace, but I also have XAMP installed as a backup but wanted to work through the workspace for ease of use.

Mark Phillips
Mark Phillips
13,124 Points

Hi Chris,

You can run the PHP code directly from the workspace by renaming the index.html file in the sidebar to index.php instead. Once you've renamed the file, click the preview icon on the right to reload that page in your browser window with the changes.

I've added my example code below to show you what it looks like with the php formatting embedded into the index.php page.

<!DOCTYPE html>
<html>
  <head>
    <meta charset=utf-8>
    <title>Mike The Frog | 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="Mike The Frog">
      </div>
      <h1>Mike Frog</h1>
      <p>Portland, OR</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">
      <p>Let's Get Started!</p>
      <p><?php echo "Hello, World!"; ?></p>
    </section>
  </body>
</html>

Let me know if this helps.