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)