I'm creating a CMS currently and one of the major features of the CMS is a datafeed system. The website is to transfer the contents of one of its databases to a large number of listing sites. Each site has its own specifications for formatting of this information, and I've been tasked with creating a backend which can be used to easily modify and add datafeeds for non-programmers.
So far, out of the formats I've recieved there three file types, XML, CSV, and TXT. There are different standards for formatting even inside these file types, different ordering of fields, some have quotations, some don't, etc. I've been puzzling over this for a while and here is my solution:
- Each feed will have a template stored in a separate database table. The templates will consist of whatever structure the feed requires (XML, CSV, TXT) with placeholder value (ex. {{NAME}}). A script will then loop through each database entry, replace the placeholders with the variable values, and save the completed document with the correct file extension.
My issue is figuring out how to save multiple files using one PHP file (perhaps calling the same file multiple times from another PHP file?) and moreover, how to save different file types like this. Basically, how do I set the extension and save the file?