954,576 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

html/php formatting question

I have only been working with php and html for a few weeks now and i had a question about where is the proper place to put the tag. Should I always put it as the second line(after the DOCTYPE) and then embed the php within it or can i put all my php code first(assuming i dont need it within my html code) and then when i actually first need html i put the tag?

kbjustin
Light Poster
29 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0
 

Your PHP can go anywhere since the browser never sees it but the doctype must be the first thing the browser sees followed by the html tag.

OK

<?php
// blahity blah
?>
<!DOCTYPE html blahity blah>
<html>


Not OK

<?php
echo 'Hello'; // this puts text before the doctype
?>
<!DOCTYPE html blahity blah blah>
<html>
ShawnCplus
Code Monkey
Team Colleague
1,583 posts since Apr 2005
Reputation Points: 526
Solved Threads: 268
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You