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 <html> 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 <html> tag?

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>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.