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 Getting to Know PHP PHP Basic Usage

add the php tags to hello world

<? php hello world?>

index.php
<?php Hello World?>
Qamar Ramzan
Qamar Ramzan
9,786 Points
<?php

echo "Hello World?";

?>

Try this

1 Answer

Jason Gilmore
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jason Gilmore
Treehouse Staff

Hi Al Barajas,

The <?php and ?> tags tell the web server to pass everything found inside those tags to the PHP interpreter. Therefore you'll want to ensure valid PHP code is contained therein. As Qamar Ramzan demonstrated above, you'll want to encapsulate the string you want to output within quotes, and then use the echo statement to tell PHP you'd like to output the string to the web page. You can also include comments within your code like this:

<?php

// Output a greeting
echo "Hello world";

?>

You actually don't even have to include the closing tag, it's optional! So you could also create a perfectly valid PHP-enabled page that looks like this:

<?php

// Output a greeting
echo "Hello world";

However when mixing PHP alongside HTML, you'll always want to include the closing tag so the web server knows which parts are PHP and which are not:

<h1>Welcome to my web page</h1>
<?php

// Output a greeting
echo "Hello world";

?>
<p>
Have a nice day.
</p>