Ran into an interesting article recently on PHP Web Site Generation using Ruby, over at codegeneration.net (the site runs a PHP section here). The article makes a good starting point for exploring what works and what doesn’t.
Think PHP is underestimated where code generation is concerned, given how easy it is to generate and dynamically execute code e.g.;
< ?php // Some code $code = '
// Write code to file
file_put_contents('generated.php',$code); # PHP5 function!
// Include the generated code for execution
Also interesting that Ruby (a dynamic language in more or less the same category as Python and Perl) was used as the generator.