Recently, Xiaoyang made a PHP classmate directory, where students can add or modify their name, email, OICQ and other information, and save it in the mySQL database. One day, Xiaoyang suddenly thought that it would be great if PHP could be used to generate a file for students to download and import the information into their Foxmail address book!
Just do it, and soon Xiaoyang launched this function. How is that achieved? Here we only explain the export of name, email address and OICQ.
If you want information, you can import it into the Foxmail address book. Of course, you must first understand the content and format of the file imported into the Foxmail address book. Open the address book of an account in Foxmail4.2, and you can see in its menu bar "Tools" - "Import" that Foxmail supports the import of two external files: "CSV file" and "Wab file". We choose to generate a CSV file. So what is the content and format of CSV files that can be imported into Foxmail? Let's first export a CSV file from Foxmail and take a look. Select a folder with a non-empty record in the Foxmail address book, execute "Tools" - "Export" - "Text File", save the file name as "TEMP.CSV", and select the output field in "Next" "Select "Name", "Email Address" and "OICQ", and click "Finish" to generate the "TEMP.CSV" file in the specified path. If you have installed the Microsoft office series, you will find that this is a file that is opened by default with EXCEL. In fact, it is a comma-separated value file of EXCEL. After double-clicking to open it, the interface will be as shown in the figure.
We still have no way of knowing its writing format in this case. Open the "TEMP.CSV" file with Notepad, and you will find that its format is very simple: as shown in the figure, the first line of the file is the field of the Foxmail address book, and the other lines are the values corresponding to the fields. Each field and value is Separated by English commas. So we generate CSV files in this format in PHP, and others can download and import them into their Foxmail!
However, there is still a problem that needs to be solved, that is, since the file uses commas as separated values, if there are English commas in the database records (Note: The following symbols refer to English unless otherwise specified) symbol)? Of course, you can first replace the commas in the data with Chinese commas, but there is actually another way, that is, if double quotes ("ie " "") are added to both ends of the corresponding fields in the CSV file to separate the values, the English commas in between It is not used as a separated value, and two consecutive English double quotes (i.e. """) in the field are only displayed as one, not as a separated value.
With these understandings, we can write the PHP file that exports the CSV file: