1

I'm making changes to a php script (include.php) that is included by many different PHP scripts which create HTML code (web pages).

The developers that maintain those web pages use different doctype, and some are complaining that validator gives them errors. They do not want to change their code - they want me to fix include.php so that it will work for them.

One problem is that some doctypes require / at the end of tags like <br>, while others don't want /

Is it possible for my include.php to determine the doctype of the script that is including it?

Ada Lovelace
  • 835
  • 2
  • 8
  • 20
  • Simply
    is sufficient for all doc types
    – Oleg Dubas Oct 04 '16 at 16:34
  • I've never used this but try http://php.net/manual/en/class.domdocumenttype.php – Monkeybrain Oct 04 '16 at 16:36
  • 1
    @OlegDubas, thats not true. xhtml requires the `
    ` tags to be self-closed.
    – Dekel Oct 04 '16 at 16:39
  • @Monkeybrain, I tried it, and it created an empty object. – Ada Lovelace Oct 04 '16 at 20:12
  • 1
    The problem is that functions like DOMDocumentType need a completed document to operate on, and presumably at the time your PHP script is running, that document doesn't yet exist, since your script is run while the document is being created. (I'm assuming that your script generates HTML, which might be a totally wrong assumption). Could you change your script to take a DOCTYPE parameter (maybe default to HTML5) and ask your users to pass that in when calling your script? – Monkeybrain Oct 04 '16 at 21:21
  • I updated my question with the fact that PHP scripts generate HTML code. The problem is that my script is being included by hundreds of scripts that I don't control. My script doesn't contain doctype, and I can't make the users pass me anything. – Ada Lovelace Oct 04 '16 at 22:44

0 Answers0