TXT tree-type classified text one-click Import Database (Fast infinite Pole classification method)

Source: Internet
Author: User
Tags import database

TXT text Format


First Class classification

Level Two classification

Level Three classification

First Class classification

Level Two classification

First Class classification

.....


(Note: You cannot have the TAB key before the first-level category, and a tab key before each level)


Here is the PHP processing code


Public function txt_category_to_mysql () {$ceng  = 0; $arr  = file (' Public/fenlei.txt "), foreach ($arr  as  $k + $v) {if (Strrpos ($v," ")  === false) {$fid  = 0;} Else if (Strrpos ($v, "")  >  $ceng  | |   $ceng  === false) {$fid  =  $id;} Else if (Strrpos ($v, "")  ===  $ceng) {$row  = m (' category ')->where ("id =  ' $id ")->find (); $fid  =  $row [' FID '];} else{$fid  =  $this->txt_category_to_mysql_get_father_category ($ceng  - strrpos ($v, ""), $id );} $ceng  = strrpos ($v, ""); $name  = str_replace ("", "", $v); $name _arr = explode (', ', $ Name), if ($name _arr[1]) {$type  =  $name _arr[1];} else{$type  =  $father _type;} $id  = m (' category ')->add (Array (' Name ' =>str_replace ("", "', $v), ' fid ' = ' $fid, ' posttime ' = Time ()));//Insert Database, this is thinkphp SQL operation, please replace the appropriate SQL statement, data as above}}public function txt_category_to_mysql_gEt_father_category ($ceng, $id) {$row  = m (' category ')->where ("id =  ' $id '")->find (); $fid  =  $row [' FID '];for ($i =0; $i < $ceng; $i + +) {$row  = m (' category ')->where ("id = " $fid ' ")->find ();             //This is thinkphp SQL query , please change your own SQL statement, data such as $fid =  $row [' FID '];if ($fid  === 0) {break;}} return  $fid;}


TXT tree-type classified text one-click Import Database (Fast infinite Pole classification method)

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.