Forum Moderators: coopster
I'm pretty new to php, and I've got a client asking if there's a way I can create a database with the contact details of their clients, and then download the list and import it into Outlook.
Basically, ths user fills out a form on the website and then that information would be stored in a mySQL database- No prob there. But what I'm wondering is how you would then take that information and write a comma seperated value list (unless there's a better way?) and then have that able to import into Outlook.
So is it possible then to use PHP to write such a file, and if so does anyone know of a tutorial or perhaps a pre-written script that would allow me to do this?
Thanks for any tips and suggestions!
Cheers,
Matt..
Do a Google Groups search on "PHP content-type CSV". This returns plenty of threads on this subject.
The long and the short of it is that a PHP script does not have to return text/html - it can return any content-type you wish - including text/csv - by using the header() function.
You then use standard PHP code to create the output, ala:
echo("field1,field2,field3\n") etc...
Also covered are ways to force the browser to offer the "Save to disk" dialog rather than try to execute it. If you don't, somebody clicking on the link on a Windows machine will probably have the CSV file unceremoniously opened into Microsoft Excel without asking!
Cheers!