Home  >  Article  >  Backend Development  >  Import data into Foxmail_PHP tutorial using PHP

Import data into Foxmail_PHP tutorial using PHP

WBOY
WBOYOriginal
2016-07-21 16:08:361254browse

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.

 Import data into Foxmail_PHP tutorial using PHP

 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!

 Import data into Foxmail_PHP tutorial using PHP

However, there is still a problem that needs to be solved, that is, since commas are used as separated values ​​in the file, if there are English commas in the database records (Note: The following symbols are not specified unless otherwise specified) What should I do if they all refer to English symbols)? 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 Not 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 and export CSV files The PHP file:

 

Run the above PHP file on the server, and open the downloaded "tofoxmail.csv" file with Notepad as shown in the figure. 🎜> Click "Tools" - "Import" - "CSV File" in the Foxmail address book... and a lot of data in the database will be imported at once. This is not a bad idea!



Import data into Foxmail_PHP tutorial using PHP (The above programs have been tested in Apache+PHP4+mySQL and IIS+PHP4+mySQL.)

http://www.bkjia.com/PHPjc/314834.html

truehttp: //www.bkjia.com/PHPjc/314834.htmlTechArticleRecently, Xiaoyang made a PHP classmate directory, where students can add or modify their names, email addresses, OICQ, etc. information and save it in the mySQL database. One day Xiaoyang suddenly thought that if it could be used...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn