简体   繁体   中英

Validating html generated by php

I'm new at web development, so to make sure I'm writing good code I've been using w3.org validation tools. I'm currently working on a project where I generate a lot of my html with php functions, and I'd like to validate the html, but w3.org doesn't support that. The only way I've found to do it is to render my code, view source and validate that, but that's an awkward, time consuming process, that only approximates validation as it renders differently in different situations. Any suggestions?

Thanks,

Rebecca

Tidy Project:

http://tidy.sourceforge.net/

http://www.w3.org/People/Raggett/tidy/

Good luck.

Edit -

To be clear, with Tidy you can be reasonably certain that the output of your script is valid against a given standard.

您可以将Html Validator加载项用于FireFox。

The various developer tools in the major browsers will help you validate the HTML your script emits.

  • IE6/7 - you can install the IE Developer's Toolbar
  • IE8 has the toolbar built in
  • FireFox - you can get the Web Developer Toolbar as an addin

I think Opera has some tools built in as well, but quite frankly I only use Opera for testing after I've built using Fx and IE.

The validator tools will not care about php, so if your php is 'bad', it won't care. It only checks html for concision and proper nesting to the doctype.

Try this, Web Developer 1.1.8 toolbar.

This ad-don works superbly, you can validate locally, for example:

Validate Local CSS

Validate Local HTLM

if you don't have access to some external web-server or even if you do have access to it.

In addition the installation is easy and to validate a given page all you have to do is right click on Tools and there is a whole array of validation options.

https://addons.mozilla.org/en-US/firefox/addon/60

Step 1: Run the PHP to generate some HTML, with a command like this:

php index.php > index.html

Make sure that php is in your system PATH variable.

Step 2: Validate this index.html with normal html validation tools.

Opera 12 is good for validating generated pages, you just go to the page, then right click and validate. that's all, so easy that scares lol.

Alternative approach: Hitchhike direct-input at the W3C validator:

( I am also facing the problem, that my staging server would need to be online, to allow for an easy validate-here link... )

The direct input at the w3c validator submits a form. Or in other words: The actual validation-page receives a POST request.

So how about: Make a link (ie in your footer) that leads to a submitForValidation.php In that php file:

  • grab the Referer-URL you just came from (through your localhost server)
  • submit as POST to the W3C page

Not done it yet, but will probably implement that soon.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM