Question:

Need someone who's really good with XHTML & PHP?

by  |  earlier

0 LIKES UnLike

OK, there's this webpage which is entirely in PHP coding. I used XHTML meta tags, they were successfully inserted, but there are a couple of PHP bugs on the page resulting from this. I ask, is this the correct way to use XHTML tags with PHP?

<doctype here>

<head>

<title, description, keyword tags>

</head>

<body>

<php coding>

</body>

</html>

 Tags:

   Report

4 ANSWERS


  1. You&#039;re missing your opening &lt;html&gt; between the doctype and opening head.


  2. No indeed it is not, you forgot that any php code goes between the &lt;?php and ?&gt; tags, also your title tag is totally messed up.

    You should also make sure that your files has the required extension, as set in your server settings file, usually this is &quot;.php&quot; when you work with php.

    The correct syntax would be something like below:

    -----CodeStart-----

    &lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1

    /DTD/xhtml1-strict.dtd&quot;&gt;

    &lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xml:lang=&quot;en&quot; lang=&quot;en&quot;&gt;

      &lt;head&gt;

        &lt;title&gt;My First Website&lt;/title&gt;

      &lt;/head&gt;

      &lt;body&gt;

       &lt;h1&gt;My First Website&lt;/h1&gt;

       &lt;p&gt;A Paragraph of Text.&lt;/p&gt;

      &lt;/body&gt;

    &lt;/html&gt;

    -----CodeEnd-----

    I don&#039;t know which reference you are using, but i highly suggest you use http://www.w3schools.com/ combined with http://www.brugbart.com/ and http://www.php.net/

    xhtml is a child language of xml, and is suposed to be served with the &quot;application/xhtml+xml&quot; mime-type, instead of &quot;text/html&quot;, this means if you have coding errors, the browser will show an error rather then the page. Some browsers do however not support this mimetype, and won&#039;t even render the page when its used. Usually the web server will serve the page as &quot;text/html&quot; for those browsers, see also: http://www.w3.org/2003/01/xhtml-mimetype...

    You can use the $_SERVER[&quot;HTTP_ACCEPT&quot;] to check if a given browser supports application/xhtml+xml See also: http://php.net/manual/en/reserved.variab...

    Having above said, the difference between xhtml and html is minimal, using a html 4.01 Strict may very well be just as good.

    The main thing to keep in mind when working with xhtml, is always to &quot;close&quot; your tags, this may be true enough when dealing with paragraphs, which wouldn&#039;t nessosearily need to be closed in HTML, it is however common practice to close your paragraphs.

    Tags like meta, link, and br would need to be &quot;closed&quot; as well. Despite that it serves no purpose to do so as of yet. It would only serve a purpose if the closing of the tag had some sort of meaning, in the case of paragraphs this might be true. But why would a given device or browser render, or threat a closed br tag (linebreak) any different then one which was not closed?

  3. Using this method you may get errors with headers already sent and a few others as the page sends the headers on reading the head section. Better is to use :

    &lt;?php

    //build your html for the body here.

    //it can be made into a string, say $display_string

    ?&gt;

    &lt;doctype &gt;

    &lt;head&gt;

    &lt;title&gt;

    &lt;!-- and the rest --&gt;

    &lt;/title&gt;

    &lt;/head&gt;

    &lt;body&gt;

    echo $display_string;

    ?&gt;

    &lt;/body&gt;

    &lt;/html&gt;

  4. Just make sure you&#039;re closing the tags properly and that you aren&#039;t trying to execute &quot;headers&quot; after whitespace or content.

Question Stats

Latest activity: earlier.
This question has 4 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.