db_collact_para_bookid.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. </head>
  5. <body>
  6. <h2>提取para?_??的内容</h2>
  7. <p><a href="index.php">Home</a></p>
  8. <?php
  9. $thisFileName=basename(__FILE__);
  10. if(isset($_GET["from"])==false){
  11. ?>
  12. <form action="<?php echo $thisFileName;?>" method="get">
  13. From: <input type="text" name="from"><br>
  14. To: <input type="text" name="to"><br>
  15. <input type="submit">
  16. </form>
  17. <?php
  18. return;
  19. }
  20. $from=$_GET["from"];
  21. $to=$_GET["to"];
  22. $filelist=array();
  23. $fileNums=0;
  24. $log="";
  25. $dirLog=_DIR_LOG_."/";
  26. $dirDb="db/";
  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. $outputFile = fopen("xml/book_link.csv", "a") or die("Unable to open file!");
  34. $aBook = array();
  35. for($iFile=$from;$iFile<$to;$iFile++){
  36. echo "<h2>$iFile</h2>";
  37. $FileName=$filelist[$iFile][1].".htm";
  38. $fileId=$filelist[$iFile][0];
  39. $inputFileName=$FileName;
  40. $outputFileNameHead=$filelist[$iFile][1];
  41. $bookId=$filelist[$iFile][2];
  42. $vriParNum=0;
  43. $wordOrder=1;
  44. $dirXmlBase="xml/";
  45. $dirXml=$outputFileNameHead."/";
  46. $currParNum="";
  47. $xmlfile = $inputFileName;
  48. echo "doing:".$xmlfile."<br>";
  49. $log=$log."$from,$FileName,open\r\n";
  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[7]==".a."){
  57. if(substr($data[4],0,4)=="para"){
  58. if($bookid=stristr($data[4],"_")){
  59. $bookid=substr($bookid,1);
  60. $aBook["{$bookid}"]=1;
  61. }
  62. }
  63. }
  64. }
  65. fclose($fp);
  66. echo "单词表load:".$dirXmlBase.$dirXml.$outputFileNameHead.".csv<br>";
  67. }
  68. else{
  69. echo "can not open csv file. filename=".$dirXmlBase.$dirXml.$outputFileNameHead.".csv";
  70. }
  71. }
  72. /*
  73. $myLogFile = fopen($dirLog."insert_db.log", "a");
  74. fwrite($myLogFile, $log);
  75. fclose($myLogFile);
  76. */
  77. fclose($outputFile);
  78. echo "count:".count($aBook)."<br>";
  79. foreach($aBook as $x=>$value){
  80. echo "{$x}<br>";
  81. }
  82. echo "<h2>齐活!功德无量!all done!</h2>";
  83. ?>
  84. </body>
  85. </html>