db_insert_commantry.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. </head>
  5. <body>
  6. <h2>提取小括号里的内容</h2>
  7. <p><a href="index.php">Home</a></p>
  8. <?php
  9. include "./_pdo.php";
  10. $thisFileName=basename(__FILE__);
  11. if(isset($_GET["from"])==false){
  12. ?>
  13. <form action="<?php echo $thisFileName;?>" method="get">
  14. From: <input type="text" name="from"><br>
  15. To: <input type="text" name="to"><br>
  16. <input type="submit">
  17. </form>
  18. <?php
  19. return;
  20. }
  21. $from=$_GET["from"];
  22. $to=$_GET["to"];
  23. $filelist=array();
  24. $fileNums=0;
  25. $log="";
  26. echo "<h2>$from</h2>";
  27. if(($handle=fopen("filelist.csv",'r'))!==FALSE){
  28. while(($filelist[$fileNums]=fgetcsv($handle,0,','))!==FALSE){
  29. $fileNums++;
  30. }
  31. }
  32. if($to==0 || $to>=$fileNums) $to=$fileNums-1;
  33. $FileName=$filelist[$from][1].".htm";
  34. $fileId=$filelist[$from][0];
  35. $fileId=$filelist[$from][0];
  36. $dirLog="log/";
  37. $dirDb="db/";
  38. $inputFileName=$FileName;
  39. $outputFileNameHead=$filelist[$from][1];
  40. $bookId=$filelist[$from][2];
  41. $vriParNum=0;
  42. $wordOrder=1;
  43. $dirXmlBase="xml/";
  44. $dirXml=$outputFileNameHead."/";
  45. $currParNum="";
  46. $xmlfile = $inputFileName;
  47. echo "doing:".$xmlfile."<br>";
  48. $log=$log."$from,$FileName,open\r\n";
  49. $outputFile = fopen("xml/commantry.csv", "a") or die("Unable to open file!");
  50. // 打开文件并读取数据
  51. $strOutput="";
  52. $Begin=false;
  53. $count=0;
  54. if(($fp=fopen($dirXmlBase.$dirXml.$outputFileNameHead.".csv", "r"))!==FALSE){
  55. while(($data=fgetcsv($fp,0,','))!==FALSE){
  56. if($data[15]=="paranum"){
  57. $currParNum=$data[4];
  58. }
  59. if($data[4]=="("){
  60. $Begin=true;
  61. }
  62. else if($data[4]==")"){
  63. $book=substr($data[2],1);
  64. $strOutput = str_replace(" .",".",$strOutput);
  65. fwrite($outputFile, "\"{$book}\",\"{$currParNum}\",\"{$data[3]}\",\"{$strOutput}\"\r\n");
  66. $Begin = false;
  67. $strOutput="";
  68. $count++;
  69. }
  70. else{
  71. if($Begin){
  72. $strOutput.=$data[4];
  73. }
  74. }
  75. }
  76. fclose($fp);
  77. echo "单词表load:".$dirXmlBase.$dirXml.$outputFileNameHead.".csv<br>";
  78. }
  79. else{
  80. echo "can not open csv file. filename=".$dirXmlBase.$dirXml.$outputFileNameHead.".csv";
  81. }
  82. /*
  83. $myLogFile = fopen($dirLog."insert_db.log", "a");
  84. fwrite($myLogFile, $log);
  85. fclose($myLogFile);
  86. */
  87. fclose($outputFile);
  88. echo "count:$count";
  89. ?>
  90. <?php
  91. if($from==$to){
  92. echo "<h2>all done!</h2>";
  93. }
  94. else{
  95. echo "<script>";
  96. echo "window.location.assign(\"{$thisFileName}?from=".($from+1)."&to=".$to."\")";
  97. echo "</script>";
  98. echo "正在载入:".($from+1)."——".$filelist[$from+1][0];
  99. }
  100. ?>
  101. </body>
  102. </html>