db_collact_para_bookid.php 2.1 KB

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