I got a-thinking the other day (I do that occassionally) and thought how great it would be to be able to separate content from code – HTML from PHP – in a similar way to Of course that quickly led me onto thinking about the Document Object Model, which allows JavaScript to interact with a HTML document and manipulate the content.

The obvious stuff would be there: innerHTML, getAttribute, setAttribute, appendChild, removeChild, getChildNodes etc. Fantastic, I thought, I could keep my logic and database-y stuff complete separate from nice clean template documents. It would be a revolution for PHP, and I would be hailed as a genius.

It’s a good job that I had a quick search to see if anyone else had done it, as someone definitely has. Not to mention it’s even part of the PHP5 core (OK, that’s actually for XML documents, but could be mangled to work with XHTML).

This has taught me two things:

  1. I’m not nearly as clever as I think I am
  2. Searching the web before opening my mouth proclaiming how great I am might save me from looking like a pillock