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 Build a Simple PHP Application Listing Inventory Items Nesting Arrays Within Arrays

Carlos Belnap
Carlos Belnap
4,564 Points

Why is my browser not "marking up" my php? Displays the same code as my text editor, including comments.

I've been following along with the lessons, and when I try to open my php file using Chrome, it just displays the "naked" code without interpreting it. My "Shirts 4 Mike" project still runs as expected, though. I recently "broke" my xampp apache server after installing webmatrix with wordpress and php. I uninstalled it, and my server runs again, but is being selective about which files it marks up. Could that have something to do with it? I'm pretty sure I re-installed xampp after uninstalling webmatrix.

<?php 

$countries = array();
$countries[0] = array(
    "code" => "US",
    "name" => "United States",
    "population" => 300000000
);
$countries[1] = array(
    "code" => "DE",
    "name" => "Germany",
    "population" => 82000000
);

?>
<?php foreach ($countries as $country) { ?>
<h1><?php echo $country["name"]; ?></h1>
<dl>
    <dt>Country Code</dt>
    <dd><?php echo $country["code"]; ?><dd>
    <dt>Population</dt>
    <dd><?php echo $country["population"]; ?></dd>
</dl>
<?php } ?>
}

Can you visit your page, copy its URL, and paste it here if possible?

Carlos Belnap
Carlos Belnap
4,564 Points

Yes, as soon as I get back home. I think you're onto something. Shows file path instead of localhost...because I'm opening with chrome instead of xampp? Doh! Thank you!

Carlos Belnap
Carlos Belnap
4,564 Points

Ryan Duchene So, I guess I took too long a break from my lessons, and forgot that I just type "localhost/filename.php" in the address bar. >_<

4 Answers

Carlos Belnap
Carlos Belnap
4,564 Points

So, I guess I took too long a break from my lessons, and forgot that I just type "localhost/filename.php" in the address bar. >_< Thanks to Ryan Duchene for putting me on the right track.

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Carlos;

After reading through your question title and your first sentence, my immediate thought was "Do you have Apache running?" You may take another look at your XAMPP installation and make sure all of your settings are correct and that all of the associated packages are up to date.

Best of luck,

Ken

Carlos Belnap
Carlos Belnap
4,564 Points

Apache shows as "running" in the control panel, ports 80 and 443. Apache is 2.4.

well, code is fine and works well here, except the last } is redundant if being fussy :). hope you'll fix apache issue, as it is one.

Carlos Belnap
Carlos Belnap
4,564 Points

Ah, thanks for noticing!

Randolph Judy
PLUS
Randolph Judy
Courses Plus Student 28,198 Points

PHP must be run on a server. If you are using XAMPP, your server's root (localhost) directory will reside in the "htdocs" sub directory of your "xampp" directory. In Windows, this is commonly "c:\xampp\htdocs". If you create a program called "my_program.php" in the "htdocs" folder, you run it in your browser using the hyperlink, "http://localhost/my_program.php". If you were to move this program to a folder with the path of "c:\xampp\htdocs\my_programs", you would run it in the browser using the hyperlink, "http://localhost/my_programs/my_program.php". If you are using another server, refer to its documentation to locate what directory to use and replace localhost with the appropriate server name if necessary.