I have pages in XHTML, the W3C validator validates them as wellformed XHTML if they are .HTML files. But they do not validate if the same file is changed to a .PHP file in notepad. I only use PHP pages when they include a PHP visitor counter. How can I make my PHP pages validate with the W3C validator?
Awestruck
Validating PHP page with W3C validator
I have plenty of PHP files that validate just fine.
Is there any actual PHP code in the file that would be changing what is actually output?
All my PHP files validate for HTML 4. The problem only occurs when I convert PHP files to XHTML and try validating as XHTML.
The code in the file is
<div>
<?
php include("counthome.php");
?>
</div>
Awestruck
It's pretty difficult to see what the problem is without seeing all the code involved and the resulting output along with the actual validation errors. Presumably the issue is in the counthome.php file, but that may be a false assumption based on the lack of information.
My question is why take a .php file and change the extension to html? PHP is parsed server side and the end result replaces the php tags within your html document prior to being sent to the web browser. Properly coded php should validate just fine.
We seem to have a communication problem.
I write pages in XHTML, the W3C validator validates them as wellformed XHTML. They are saved as HTML files. If I then save the same files as *.php so that my PHP page counters work, theXHML validator says the DTD is all wrong. The changes from PHP to HTML and vice versa are purely experimental to try and track down the cause of the problem.
Awestruck
I've found it easier to develop the PHP pages and either give the validator the URL or copy and paste the generated source code to the validator. The validator cannot validate PHP code.
By any chance are you uploading the file to the W3C validator? If so, realize that the validator is not going to parse the embedded PHP code; rather it will treat it as an unknown/invalid tag. You need to either save the .php file on a web accessible location and supply the URL to the validator so that it can access the output from your web server, or else load the page locally from your localhost PHP installation and then validate the [X]HTML generated by it. This could be done by doing a "view source" and copy-and-pasting the HTML, or as I do by using the Firefox Web Developer plug-in and simply doing a "Tools -> Validate Local HTML" menu option.
Or, as you suggested, "What we have here is a failure to communciate."
I've been using the web developer extension for at least 2 years now ... thanks for pointing out there is a local validator.
NogDog;10891320 wrote:Or, as you suggested, "What we have here is a failure to communciate."
The story of the internet (well, that and porn...)
Hello NoDog
As I have said several times,my problem is with the W3C XHTML validator. I want the W3C logo to appear on my pages. Even if I remove the embeded PHP code it refuses to validate a PHP file.
Hello Kudos
I have been doing exactly what you recommend. Thanks for pointing out that the W3C XHTML validator cannot validate files with the PHP suffix, no wonder it would not validate. Quite an oversite on W3C's part.
Thanks to you all
Awestruck
Sorry Awestruck, but I didn't say that nor intended for you to interpret what I said that way.
The W3C validator can validate pages with any extension, but it only validates the [X]HTML generated from the page.
For example, if I have a dynamic web site using PHP (i.e. http://spechal.com/index.php), I can view the generated source code and copy and paste validate it, or I can enter the URL into the W3C web site and have it validate it.
You cannot take the source code of the PHP file and validate it, you have to validate the generated code ... i.e. when you select View Source with your browser.
Awestruck wrote:Thanks for pointing out that the W3C XHTML validator cannot validate files with the PHP suffix, no wonder it would not validate. Quite an oversite on W3C's part.
To repeat what Kudose said, the W3C validator does not care what extension appears in the URL, it only cares about the content of the page. The URL has nothing to do with validation. If you don't believe me, have a look at some of the pages on the W3C site and have a look at the file extensions in their URLs (incidentally, the validator's front end is itself written in Perl).
Thank you both for being so patient.
I am pleased to hear that W3C XHTML validator will validate a PHP file
I always enter the URL of the php file thinking that the W3C validator is then scanning a generated page. It always complains about the Doc type and then does a report on the page but refuses to validate fully until the doctype is sorted. I enter the doctype suggested by W3c but it still refuses to fully validate. I have used every doctype possible but it still refuses. I will try your suggestion of copying and pasting from my website and then let you know what happens. I will also let you see the doctype and the resulting error message.
Awestruck
If it's not too private or such, a link to the problematic page in question would probably be a great boon to us helping you resolve what the problem is.
I realize this is older post but for the people that still come here looking for information I will post
I do this all the time to validate against 1.0 and 5 using the W3C tools
- take the completed or hopefully completed php page and put it on your server (home server or hosted deos not matter)
- bring up the page in several different browsers to insure that the rendered page formatting is acceptible to you in all cases
- when the page is the way you want it RIGHT CLICK the page in the browser and select VIEW SOURCE
- Copy and paste it to a text editor and save it as .html or .xhtml does not matter
- Go to the W3C validate page and select the validate a file option
- browse to where you file is and load it in and press validate
- correct the issues
- change the doctype
- do it again
By doing this I can validate against 1.0 and html5 or any other doctype I want. usually I only do the 1.0 and 5
using this process will allow you to see the direct connection of rendered php outputs and html or xhtml validation
Have fun
@: How is what you're suggesting any different than the way such validation has always been done?
Client-side language validators (such as the HTML validator W3C provides) have no idea what scripting language you're using, if any. Using PHP to generate an HTML webpage is no different than using a plain .html file or even some new server-side language that hasn't even been invented yet. In the end, the client is never any wiser and simply processes whatever output it receives.
In other words, I don't see how the process you described above is any different than before PHP was even invented; in the end, you've got some HTML/client-side language that you want client's browsers to interpretet correctly. That's it.
In fact, W3C's validator allows you to specify a URL, so there's no need to even save the outputted HTML webpage at all.
Agreed, and if you are concerned with render time, use the Firebug FireFox extension to see what request are taking what amount of time and if the requests are note taking the time to render the page but the application itself, look into using xhprof or another application profiling tool.
you say the same php page validates correctly if you remove the php codes from it, am I right?
I don't think anyone here has said that... mostly because that makes absolutely no sense?