Skip to content

TextMate: W3C HTML Validation For Local PHP Files

Categories: Uncategorized

Table of Contents

It is impossible to validate local PHP files via the built in W3C validation that the TextMate HTML bundle provides because it does not parse the PHP code in the PHP document. I’ve modified the default validation script to retrieve the file using OS X’s built in apache server (the script assumes you have your files in the ~/Sites directory) so it will work for not only PHP, but any apache-interpreted language. I’ve added the ss option to the W3C validator, you can add/remove any validation options to the curl command as you see fit.

[code lang=”bash”]
#!/usr/bin/env ruby -wKU
STDOUT.sync = true

page = `echo $TM_FILEPATH | sed “s|.*/$USER/Sites/|http://localhost/~$USER/|” | xargs curl -s`

open(‘|curl -sF uploaded_file=@-;type=text/html -F ss=1’, ‘r+’) do |io|
io < < page; io.close_write while io.gets $_.gsub!(//, ‘&‘)
puts $_

Hope everyone had a blessed and happy easter!