PhpMyCodeGenerator and PhpMyCellScript


PhpMyCodeGenerator is a code generator framework, which allows you to create code generators as PHP functions and provide input to the code generators through an Excel/Calc file, such that you can create a simple code generator within several minutes, prepare you input data via the easy-to-use Excel/Calc, and start code generation by a boilerplate command.

The framework core (excluding PhpMyCellScript) consists of only several hundred lines of code, so it should be easy for you to understand and make use of the framework to create your personal code generators.

How to create a code generator?

  1. Prepare a PhpMyCodeGenerator script, say test.php. A code generator is a PHP function whose name starts with "gen_". Example:
    include_once 'PhpMyCodeGenerator.php';
    PhpMyCodeGenerator::main($argc, $argv);
    function gen_echo($excel, $worksheet) {
     assert('PhpMyCodeGenerator::version >= 2');
     $last_cell = $worksheet->Cells(1, 1)->SpecialCells(11);
     for ($i = 1; $i <= $last_cell->Row; $i++) {
      for ($j = 1; $j <= $last_cell->Column; $j++) {
       echo PhpMyCodeGenerator::quoteCsvField($worksheet->Cells($i, $j)->Value), "\t";
      echo "\n";
  2. Prepare input data in an Excel file, say test.xls:
    test.xls (echo - test)
  3. Start code generation by:
    php test.php test.xls
  4. Output:
    "1" "2" 
    "3" "4"