combin_all_word_by_book.php 1.3 KB

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