Converting to PHP

Php is being used to reduce dup code and redundancy.