Jump to content

Recommended Posts

I have just started using PHP. I have always for my HTML used doctypes, XHTML 1.0 usually. Now that I'm using php, I have a question. When I put a doctype at the top of the php doc, the page doesn't appear. But when I remove it, everything's fine. Is there such thing as a doctype? Because I fail validation if I don't have a doctype. Is the solution to use

<?php
echo "put the doctype here";
?>

at the top of the page so that when the browser (or validator) sees the page it sees the doctype? I'm not sure what to do here! Please help. Thanks.

Link to comment
Share on other sites


give us an example of code that doesnt work.

in php you must have <?php before any code otherwise it wont recognise it as php information. Also are you creating a page dynaically using the php?

e.g. are you trying to create a standard page using php scripting

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
......

in php this would be

<?php
echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'
echo '\r\n<html>\r\n<head>\r\n'
....
?>

or

<?php
print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">"
print "\r\n<html>\r\n<head>\r\n"
....
?>

echo and print are interchangable in this application, and in the second one ive used only double quotes and \" for any internate double quotes for the printed string.

Link to comment
Share on other sites

There is a list of available doctypes at the following pages:

http://hsivonen.iki.fi/doctype/ (contains more in depth info)

http://www.w3schools.com/tags/tag_doctype.asp

http://htmlhelp.com/tools/validator/doctype.html

As for outputting the doctype...

You can use the method phkninja declares or you can just add it in to the very top of your PHP outside the php tags. Such as:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd"> 
<html>
<head>

<?

//insert your php coding here

?>

Php will output anything not in php tags just as it is. Thus allowing you to output non-dynamic html without the fuss of having to enclose it in a variable. Also to note - if you are not sticking to a strict standard and wish for alot of flexibility, I would personally recommend using HTML 4.01 transitional.

Edited by Chozo4
Link to comment
Share on other sites

I figured it out! :thumbup

I used the method described by phkninja. I'm not using dynamicy stuff, just using php for the require() function because I am sick of having to copy-and-paste the same header and footer onto every single page. I was being stupid because I just started to use php and I realized that the included pages for the footer and header were full html docs but now I realize it has to be just snippets and the end result is in html form which is what I was validating. It all works now. Thanks all.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...