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:
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?
You save multiple files like you save the first one.
If you have the files contents in $filecontent
, and the filename to be used (with appropriate extension) in $filepath
, you can use
file_put_contents($filename, $filecontent)
Do that in your loop and you’re done.