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

"Hello, World!" is not displaying on my page?

I know that I've typed the code right. But it still dosen't display??

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Let´s check the obvious first. Have you saved your file, refreshed the page in the browser and as a last resort tried clearing the browser cache and refreshing again? Oh and you're doing this in workspaces correct? If you're doing it locally you need to set up a php server.

Konrad Pilch
Konrad Pilch
2,435 Points

Whats happening though? Can you say in more details pelase? Does the page goes all blank? or soemthing? Could you show us the code?

Simon Coates
Simon Coates
28,694 Points

The correct code for outputting hello world would be:

<?php
echo "hello world";

You can try running your code in a PHP sandbox (eg http://sandbox.onlinephpfunctions.com/)to verify correctness. Otherwise, we need to know the details of how your code is not working (environment, whether you're accessing the right page etc.) As Konrad Pilch notes, i did omit the closing tag, and i don't doubt there are points at which doing so is not advised. I'd also note that online sandboxs aren't fully featured, but should be okay for a hello world program, or debugging small fragments of PHP code.

Konrad Pilch
Konrad Pilch
2,435 Points

Simon, thats partially correct - depending on the situation.

The code should open PHP tags, and close, in between the code. What you have, it would break my whole aplication where im trying to display user username. Its good for things like classes because thers no html, only PHP, so you don't need to close the PHP tag, and it's better not to.

1 Answer

It's a bit embarrassing.. I forgot to change "index.html" to "index.php"....

Thanks anyways!

Robert Cooper
Robert Cooper
22,704 Points

I did the exact same thing and it took me a while to figure it out...haha