PHP

Arthur Kakulidis
Arthur Kakulidis
1,665 Points

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
11,632 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 :)

Arthur Kakulidis
Arthur Kakulidis
1,665 Points

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
11,632 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

Arthur Kakulidis
Arthur Kakulidis
1,665 Points

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