标签:
1,php从文本逐行读入数据,保存到数据组。使用fopen读取文本内容,逐行读取文本是$majorId = trim(fgets($rfile, 4096));。
$rfile = fopen("cate_id.txt", "r"); if ($rfile) { while (!feof($rfile)) { $majorId = trim(fgets($rfile, 4096)); $majorName = CategoryNamespace::getMajorCategoryById($majorId); if(!$majorName){ $majorName = CategoryNamespace::getMinorCategoryById($majorId); } $majorArray[$i][‘id‘] = $majorId; $majorArray[$i][‘name‘] = $majorName[‘name‘]; $i++; } fclose($rfile); }
2,将数组数导出到文本,将数组内容拆分为字符串,将字符串导出到文本。
$majorStr = "majorId"."\t"."majorName"."\n"; $wfile = ‘cate_result.txt‘; foreach($majorArray as $major){ $majorStr = trim($majorStr.$major[‘id‘])."\t".trim($major[‘name‘])."\n"; } file_put_contents($wfile, $majorStr);
标签:
原文地址:http://www.cnblogs.com/usa007lhy/p/5221761.html