How does php read txt text and store it in the mysql database?

Source: Internet
Author: User
How does php read txt text and store it in the mysql database! This post was last edited by pigpigpighappy from 2012-12-1717: 07: 47! How does php read txt text and store it in the mysql database? Complete Code! Suitable for extra points! Thank you! ------ Solution --------- How does php read txt text and store it in mysql database!

This post was last edited by pigpigpighappy at 17:07:47, January 17 ,.

Please help me! How does php read txt text and store it in the mysql database? Complete Code! Suitable for extra points! Thank you!


------ Solution --------------------
It depends on whether your txt file is written in the form of database fields. If yes, I will do this, and I will use txt to add an email address.
Each line requires only one address

// Upload txt text
If ($ _ FILES ['text'] ['name']) {
$ Path = '../upload ';
If (! File_exists ($ path )){
Mkdir ($ path );
}
If (! Is_dir ($ path )){
Mkdir ($ path );
}
$ P = strrchr ($ _ FILES ['text'] ['name'], '.');
If (preg_match ("/txt/", $ p )){
$ File = $ path. '/'. date ('ymmd'). time (). $ p;
Move_uploaded_file ($ _ FILES ['text'] ['tmp _ name'], $ file );

$ Get = fopen ($ file, 'r ');
$ J = 0;
While (! Feof ($ get) {// read each row cyclically
$ Row = fgets ($ get );
$ Row = str_replace ('','', $ row );
$ Rowa = preg_match ("// \@/", $ row );
$ SQL = "INSERT INTO 'address' ('address', 'timees', 'data') VALUES ('". $ rowa. "', '0', 1 )";
$ Db-> guery ($ SQL );
$ J ++;
}

}
Echo "script" alert ('added $ j'); history. back (); script ";
}
} Else {
Echo "script" alert ('select the correct adding method'); history. back (); script ";
}
Fclose ($ get );

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.