db_collact_para_bookid.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. # 用拆分好的三藏数据 导出cs6段落编号
  3. require_once '../public/_pdo.php';
  4. require_once '../path.php';
  5. if ($argc < 3){
  6. echo "无效的参数 ";
  7. exit;
  8. }
  9. $from = (int)$argv[1];
  10. $to =(int)$argv[2];
  11. if($from<1){
  12. $from = 1;
  13. }
  14. if($to>217){
  15. $to = 217;
  16. }
  17. $filelist=array();
  18. $fileNums=0;
  19. $log="";
  20. $dirLog=_DIR_LOG_."/";
  21. $dirDb="db/";
  22. if(($handle=fopen("filelist.csv",'r'))!==FALSE){
  23. while(($filelist[$fileNums]=fgetcsv($handle,0,','))!==FALSE){
  24. $fileNums++;
  25. }
  26. }
  27. $outputFile = fopen(_DIR_PALI_CSV_."/book_cs6_para.csv", "w") or die("Unable to open file!");
  28. $aBook = array();
  29. for($iFile=$from-1;$iFile<=$to-1;$iFile++){
  30. echo "doing $iFile ";
  31. $FileName=$filelist[$iFile][1].".htm";
  32. $fileId=$filelist[$iFile][0];
  33. $inputFileName=$FileName;
  34. $outputFileNameHead=$filelist[$iFile][1];
  35. $bookId=$filelist[$iFile][2];
  36. $vriParNum=0;
  37. $wordOrder=1;
  38. $dirXmlBase=_DIR_PALI_CSV_."/";
  39. $dirXml=$outputFileNameHead."/";
  40. $currParNum="";
  41. $xmlfile = $inputFileName;
  42. # $log=$log."$from,$FileName,open\r\n";
  43. // 打开文件并读取数据
  44. $strOutput="";
  45. $Begin=false;
  46. $count=0;
  47. if(($fp=fopen($dirXmlBase.$dirXml.$outputFileNameHead.".csv", "r"))!==FALSE){
  48. while(($data=fgetcsv($fp,0,','))!==FALSE){
  49. if($data[7]==".a."){
  50. if(stripos($data[4],"para")!==false){
  51. if($bookid=stristr($data[4],"_")){
  52. $bookid=substr($bookid,1);
  53. $paraString = stristr($data[4],"_",true);
  54. $paraBegin = stripos($paraString,"para")+4;
  55. $paraNum = explode("-",substr($paraString,$paraBegin));
  56. $count++;
  57. $output = array();
  58. $output[] = substr($data[2],1);
  59. $output[] = $data[3];
  60. $output[] = $bookid;
  61. foreach ($paraNum as $key => $value) {
  62. # code...
  63. $output[] = $value;
  64. }
  65. if(count($paraNum)==1){
  66. $output[] = $paraNum[0];
  67. }
  68. fputcsv($outputFile,$output);
  69. }
  70. }
  71. }
  72. }
  73. fclose($fp);
  74. echo "$count \n";
  75. }
  76. else{
  77. echo "can not open csv file. filename=".$dirXmlBase.$dirXml.$outputFileNameHead.".csv \n";
  78. }
  79. }
  80. /*
  81. $myLogFile = fopen($dirLog."insert_db.log", "a");
  82. fwrite($myLogFile, $log);
  83. fclose($myLogFile);
  84. */
  85. fclose($outputFile);
  86. echo "齐活!功德无量!all done! \n";
  87. ?>
  88. </body>
  89. </html>