Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.03 KB | None | 0 0
  1. <?PHP
  2. if(!is_array($argv) || !array_key_exists(1,$argv))
  3.         die("Please supply the drive_offsets.html file as an argument.\n");
  4.  
  5. $filepath = $argv[1];
  6. $filedir = dirname($filepath);
  7. $page=file_get_contents($filepath);
  8. unset($filedir);
  9. unset($filepath);
  10. preg_match("/<table[^>]*>(.+)<\/table>/is", $page, $matches);
  11. $page=$matches[1];
  12. preg_match("/<table[^>]*>(.+)<\/table>/is", $page, $matches);
  13. unset($page);
  14. $htmldata='<html><body><table>'.$matches[1].'</table></body></html>';
  15. unset($matches);
  16. //var_dump($htmldata);
  17. $doc = new DOMDocument();
  18. $doc->loadHTML($htmldata);
  19. $rows = array();
  20. foreach( $doc->getElementsByTagName( 'tr' ) as $tr ) {
  21.     $cells = array();
  22.     foreach( $tr->getElementsByTagName( 'td' ) as $td ) {
  23.         $cells[] = $td->nodeValue;
  24.     }
  25.     $rows[] = $cells;
  26. }
  27. unset($cells);
  28. unset($doc);
  29. //var_dump($rows);
  30.  
  31. for ($i=1;$i<count($rows);$i++)
  32.  echo "INSERT INTO drives(Name,Offset,Submissions,Percent_agree) VALUES('".$rows[$i][0]."','".$rows[$i][1]."','".$rows[$i][2]."','".$rows[$i][3]."');\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement