I took a closer look at DeviceTemplate2php.php. PHP evaluates variables ($words) and escape characters (i.e. \r \n) in strings automatically whenever it sees them in "double quotes". In single quotes on the other hand, PHP does not evaluate them.
How $words and /n, /r, etc are interpreted in nested mixed single and double quotes are interpreted by PHP is extremely hard to figure out. I'm not even sure that interpretation of nested quotes in PHP is clearly defined. In any case, when you have PHP code, sql statements, and ruby code all supposedly delimited by the same quotes that are included in the PHP code, sql statements, and ruby code it quickly turns into madness.
Maybe someone who is expert at PHP, sql, and ruby could unravel this script to make it work. I think, however, the simplest solution is to rewrite the same script using a different language. A language that has good sql support and string interpretation rules that lend themself to this sort of thing is key.
I also think that if it is rewritten, the usage ought to be more like this:
To export:
ExportDeviceTemplate 1932
which would produce a file called "1932.dt".
To import:
ImportDeviceTemplate 1932.dt
Ideally the .dt files would be in a format that can be easily diffed.
If I can find the time I might undertake this myself. I think it is important to be able to share device templates. I think there might also be a role for import/export of device templates even when sqlCVS is working well -- device templates ought to be tested on a variety of installations before they are permanently committed to the code base.
Regards,
Alex