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

How do you add php to your html document(if you can)? If not, how do I start a php file?

I am starting to learn php and do not know how to insert php in to my files. I know how with jQuery you use the script tags, and download jquery version. What do you do with php.

3 Answers

Adam Woloszyn
Adam Woloszyn
12,782 Points

You cannot add PHP code to a .html file. Two requirements for using php 1) File name must end with .php 2) Have PHP tags in the file. Example below.

Filename: helloworld.php

File Contents:

<?php echo('Hello World'); ?>

You can however add HTML to a PHP file. Example

<?php echo('<p>Hello World</p>'); ?>

Hopefully this helps :)

I'm sorry if this is a stupid question... but if I want to use php in my website, how do I do that? Since you can't write php in an html file?

Adam Woloszyn
Adam Woloszyn
12,782 Points

Hi Arthur, Have you taken this course yet? https://teamtreehouse.com/library/php-basics-2 It should cover all of the basics and hopefully explain, better than I, how to achieve what you're looking for. Adam

Thank you, I found the exact video that explained the problem I had.