combin_all_word_by_book.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. </head>
  5. <body>
  6. <p><a href="index.php">Home</a></p>
  7. <h2>合并以书为单位的单词表</h2>
  8. <?php
  9. $dirXmlBase="xml/";
  10. $filelist=array();
  11. $fileNums=0;
  12. $log="";
  13. if(($handle=fopen("filelist.csv",'r'))!==FALSE){
  14. while(($filelist[$fileNums]=fgetcsv($handle,0,','))!==FALSE){
  15. $fileNums++;
  16. }
  17. }
  18. $outputfile=$dirXmlBase."all_word_book.csv";
  19. if(($fpoutput=fopen($outputfile, "w"))!==FALSE){
  20. $wordCountCsvHead=array("book","word","count","prsent","length");
  21. fputcsv($fpoutput,$wordCountCsvHead);
  22. }
  23. else{
  24. echo "can not open csv file. filename="."_count.csv";
  25. }
  26. $g_paliWordCounter=0;
  27. for($i=0;$i<count($filelist);$i++)
  28. {
  29. $bookid=$filelist[$i][2];
  30. $outputFileNameHead=$filelist[$i][1];
  31. $dirXml=$outputFileNameHead."/";
  32. $inputFileName=$dirXmlBase.$dirXml.$outputFileNameHead."_analysis.csv";
  33. echo "doing:[$i] - $outputFileNameHead <br />";
  34. if(($handle=fopen($inputFileName,'r'))!==FALSE){
  35. $iLineNum=0;
  36. while(($data=fgetcsv($handle,0,','))!==FALSE){
  37. if($iLineNum>0){/*skip first line*/
  38. $data[0]=$bookid;
  39. fputcsv($fpoutput,$data);
  40. }
  41. $iLineNum++;
  42. }
  43. }
  44. else{
  45. echo "open file:".$inputFileName." false<br>";
  46. }
  47. fclose($handle);
  48. }
  49. fclose($fpoutput);
  50. echo "all done!";
  51. ?>
  52. </body>
  53. </html>