Import data to Foxmail using PHP

Source: Internet
Author: User
Recently, Xiaoyang made a PHP transcript where students added or corrected their names, email addresses, OICQ, and other information and kept them in the mySQL database. One day, Xiaoyang suddenly thought that if I could use PHP to generate a file for students to download and put these materials

Recently, Xiaoyang made a PHP transcript where students added or corrected their names, email addresses, OICQ, and other information and kept them in the mySQL database. One day, Xiaoyang suddenly thought that it would be nice to use PHP to generate a file for students to download and import these materials into their Foxmail address book!

Just do it, and soon Xiaoyang will launch this function. How is that implemented? Here, we will only elaborate on the exported name, email address, and OICQ.

Materials can be imported into the Foxmail address book. of course, you must first understand the content and structure of the files imported into the Foxmail address book. Open the address book of an account in Foxmail4.2. in the menu bar "tools"-"import", you can see that Foxmail supports the import of two types of external files: "CSV file" and "Wab file ". We select a natural CSV file. What is the content and structure of CSV files that can be imported into Foxmail? Let's first export a CSV file from Foxmail. In the Foxmail address book, select a folder with no Blank Records, perform "tool"-"export"-"text file", and keep the file name as "TEMP. CSV. in "next", select "name", "email address", and "OICQ" in "select output Field ", after clicking "finish", the "TEMP" is created in the specified path. CSV file. If you have installed the Microsoft Office series, you will find that this is a file opened by default in EXCEL. In fact, it is a comma-separated value file in EXCEL. after you double-click it, its interface is displayed.

In this case, we still cannot know its writing pattern. Set "TEMP. the CSV file is opened in Notepad, so that the layout of the file is very simple: the first line of the file is the field in the Foxmail address book, and the other lines are the value corresponding to the field, fields and values are separated by commas. Therefore, in PHP, a CSV file is generated based on this pattern, and others can download and import it to their Foxmail!

However, there is another title that needs to be resolved, that is, since the file is separated by commas (,), what should we do if the database records contain English commas? Of course, you can replace the comma in the data with a Chinese comma, but there is another way, that is, if the two ends of the corresponding fields in the CSV file are added with double quotation marks ("That is ''") separate values. the comma in the field is not used as the separator value, and the two double quotation marks ("'' ") in the field are displayed only as one, not as the separator value.

With these familiarity, we can compile the php file for exporting CSV files:

Using dfname+'tofoxmail.csv '; // The inherent file name.

// Connect to the mySQL database:
Mysql_connect ('localhost', 'yourname', 'yourpassword') or die ('cannot connect to the database! ');
Mysql_select_db ('alumni') or die ('database generation error! ');

If ($ action = 'download '){

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.