I normally use http://validator.w3.org/ to validation my XHTML, however, in my current project, I've used PHP as well & all my files has ".php" extention so can't use this site to validation my XHTML codes. Mainly the PHP I've used is for the "include" function to share navigation, header, footer, etc. across all the pages.

How do I go about validating these pages (having extention ".php" but has "xhtml" codes within).

One of the example is of Privacy page i.e. "Privacy.php":

<div id="header">
<?php include("inc/header.inc");?> 
</div>

<?php include("inc/head.inc");?>

<body>
<?php include("inc/banner_topmenu.inc");?>
<?php include("inc/left_right_content.inc");?>

<div id="centerContent">
<p class="first-letter">
This privacy statement discloses the privacy policies of All Inclusive Web Design. It applies solely to this website itself along with its content <span class="italic">(text and images)</span>. All Inclusive Web Design is committed to respecting your privacy. We have structured our website so that, you can visit it without identifying yourself or revealing any personal information.</p>

<p>Under the Data Protection Act 1998, we have a legal duty to protect any personal information we collect from you. We do not pass on your details to any third party. Your visit to All Inclusive Web Design is anonymous and hence no personal information is recorded or gathered, unless when you fill in the contact form to contact us.</p>

<p>If you do not wish to be contacted using any of the details you provide us through the Contact form, please say so when sending the form.</p>
</div>

<?php include("inc/footer.inc");?>

</body>
</html>

    You can't use HTML validation on a PHP file, because it's impossible to know in advance every possible HTML file it could produce.

    Your best bet would be to use a client-side validator for example, the Firefox extension "HTML Validator" to check the pages after they're generated during system testing.

    Mark

      Basically when using HTML tags with empty elements like img hr br ect just write as

      <br /> <hr />  <img /> <area /> <base /> <frame /> <input /> <link /> <meta /> <param />

      also use lowercase for tags when you are generating your HTML and it should validate since that is what it is looking for and I suppose proper closing of tags as well

      <b><center>Test</b><center>This line works but is wrong...improper close
      <b><center>Test 2</center></b>This line is right it was properly closed.

        The firefox HTML validator is really handy when making a page that you need to make sure validates.

        Note how this page has 2 errors and 113 warnings. Even google has warnings.

          MarkR wrote:

          You can't use HTML validation on a PHP file, because it's impossible to know in advance every possible HTML file it could produce.

          Your best bet would be to use a client-side validator for example, the Firefox extension "HTML Validator" to check the pages after they're generated during system testing.

          Mark

          I've seen many website with pages having ".php" extention although has "XHTML" validation image. How do they validate their page ???

          How about, if I get rid of all the "include" tags & save file with ".html" extention & then try validating it. Once I sort all the errors out, I would save my file back again with ".php" extention & then display "XHTML validator" graphic (http://party.traas.org/images/xhtml11.png) on my website.

          Would that be right thing to do ???

            Nope. Nope. Nope.

            Unless I am really missing the point of your question, you can feed the address of your php page directly into the w3c validator. It could care less what the extension is. It's only going to validate whatever is actually generated.

              j4mes_bond25, did u ever try to validate your php pages befor came here and open a stupid thread?

              php, generate code: html, xhtml, xml or anything u want, did u ever try to add in validator.w3.org the url to your page: http://www.j4mes-bond25.com/my_php_page.php to see if he can validate it?

              ONE QUESTION:
              WHAT DOES XHTML VALIDATION HAS TO DO WITH PHP?

                bogu wrote:

                j4mes_bond25, did u ever try to validate your php pages befor came here and open a stupid thread?

                php, generate code: html, xhtml, xml or anything u want, did u ever try to add in validator.w3.org the url to your page: http://www.j4mes-bond25.com/my_php_page.php to see if he can validate it?

                ONE QUESTION:
                WHAT DOES XHTML VALIDATION HAS TO DO WITH PHP?

                Hmmmm.......... Charming !!! With this language of yours, I reckon, your future is rather bright as a Bin Laden's henchmen. It highly gives a hint that your communication skills along with manners & etiquette stopped developing since puberty, I'm afraid.

                Secondly, I've tried XHTML enough times in the past, however, as far as the PHP itself is concerned, I'm afraid, this was actually the first time, I'd a chance doing so.

                I tried typing the entire web address, but I rather fancied doing it page by page, instead of having the entire website's error getting displayed all at once.

                Lastly, I was little at sea about XHTML validation solely validating .html pages & hence when I came across the error message, which was beyond me, I assumed the error was due to the ".php" file.

                I'm terribly sorry to have you disappointed with my thread, but I wonder if anyone stopped you accessing your basic human right of merely IGNORING the thread itself, rather than getting brassed off with my presence.

                  The language of bogyou's post was uncalled for, but it is true that ahundiak gave you the answer (twice).

                    Installer wrote:

                    The language of bogyou's post was uncalled for, but it is true that ahundiak gave you the answer (twice).

                    I agree.......... with both points. It's all cleared now. Reason I was bit at sea was the website said it's XHTML validator, while I had PHP extention with each files having links of 3-4 other "inc" files & hence as soon as I saw the error, I'd a feeling that it's all down to "php" extention, since I remember seeing something on the website which said the website doesn't presently support such document & hence was seeking for the alternate way I could validate my page.

                    However, am glad to know that files with .php extention can also be validated in "xhtml" validator.

                      Ooooo, come on, how is my language? just because I make he's post a stupid one?
                      Hmmm, maybe sometimes is better to ignore ...

                      If I ever offended u, then, "I'm sorry ..."

                        bogu wrote:

                        Ooooo, come on, how is my language? just because I make he's post a stupid one?
                        Hmmm, maybe sometimes is better to ignore ...

                        If I ever offended u, then, "I'm sorry ..."

                        Well, I respect your viewpoint, although, not necessarily agree with you, I'm afraid.

                        I'm yet to dip my toe in PHP & hence what's often beyond me could be seen as rather obvious/easy/stupid to someone who's already a dab hand at it.

                        Seems like "darkred" is your favourite colour then 😉

                          I couldn't just copy & paste the code, since it's "php's include" file & hence the necessary codes of "head" & "body" tags, etc. are in different files, so it won't validate.

                          I then tried using the "browse" button & then selected the file I wanted to validate, but came across the error message saying:

                          "Sorry, I am unable to validate this document because its content type is application/x-php, which is not currently supported by this service."

                            Does this mean you're still having trouble?

                              The problem is that you're trying to upload the file. You want to link to the file live on a server so that the validator can see the full output.

                              Generally, when writing your code, if you code everything that will be output on the page in XHTML, making sure that you end your tags, even when you have multiple ifs or a switch in place, or god knows what else generating your content, (how many commas can I use to separate this sentence), you should be in line for fully compliant XHTML.

                              There is a spider validator that will validate all of the pages of a site:
                              http://www.htmlhelp.com/tools/validator/
                              but if any of your pages has recursive links, it'll get stuck on that page. (Example: I have a site that has a "schedule" page, and the next button goes to the next week... and the next... and the next... and the next... and the...)

                              But it can really help point out any basic things.

                              Another thing to check is pages that have had data posted to them (as the validators won't check these) you can save a page that has been generated as html (file-> save as...) and then upload it to the validator.

                              Let me just say this: there will always be one that you miss 😉

                                You can also copy-and-paste the generated HTML into the supplied input form.

                                  Weedpacket wrote:

                                  You can also copy-and-paste the generated HTML into the supplied input form.

                                  Yes, you're right. What I now did was rather than coping the ".php" file's code OR browsing & selecting ".php" file. I actually RAN the .php file & then "view source" & copied the HTML codes, which I copy & pasted in the space provided at validator's website.

                                  It now works perfectly well, except few minor errors, which I'd spend time in resolving myself, one by one. Thanks for your time, help & effort. Much appreciated.

                                  By the way, since this is the first time I'd used "embed" to include "flash's .swf" file, most of the errors is within this, such as:

                                  Line 19 column 49: there is no attribute "height".
                                  
                                  <embed src="banner/banner_unanimated.swf" height="150" width="700"></embed>
                                  
                                  Line 19 column 66: element "embed" undefined.
                                  
                                  ...ner/banner_unanimated.swf" height="150" width="700"></embed>
                                  

                                  Any idea about any of these errors ??? Firstly, I thought, its the error to do with missing "alt" (as in "img src", you have to have "alt") but that seems not the case.

                                    It should be "<embed />", not "<embed></embed>", but since it's deprecated anyway....you should use "<object></object>".

                                    Edit: In the next post, ahundiak is right. Rather than being deprecated, "embed" is not even in XHTML.