Advertisement
Guest User

abc def db parser

a guest
Jul 30th, 2014
460
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.41 KB | None | 0 0
  1. <?php
  2.  
  3. $config['mysql_host'] = 'localhost';
  4. $config['mysql_user'] = 'user';
  5. $config['mysql_password'] = 'password';
  6. $config['mysql_base'] = 'db';
  7.  
  8. $mysql = mysql_connect($config['mysql_host'],$config['mysql_user'],$config['mysql_password']);
  9. mysql_select_db($config['mysql_base'], $mysql);
  10. mysql_query("SET NAMES 'utf8'", $mysql);
  11. mysql_query("TRUNCATE TABLE `abcdef`", $mysql);
  12.  
  13. $filename=array(
  14.     'DEF-9x.html',
  15.     'ABC-3x.html',
  16.     'ABC-4x.html',
  17.     'ABC-8x.html'
  18. );
  19.  
  20. $re='@<tr><td>(\d+)</td><td>(\d+)</td><td>(\d+)</td><td>(\d+)</td><td>(.+)</td><td>(.+)</td></tr>@umx';
  21.  
  22. foreach ($filename as $fn){
  23.     print($fn."\n");
  24.     $txt = file_get_contents($fn);
  25.     $txt = iconv ('cp1251','utf8',$txt);
  26.     $txt=str_replace("\t",'',$txt);
  27.  
  28.     preg_match_all($re,$txt,$result,PREG_SET_ORDER);
  29.     foreach ($result as $match){
  30.     $region_last = trim(preg_replace("/.*\|/Uu", "", $match[6]));
  31.     $region_first = trim(preg_replace("/\|(.*)$/Uu", "", $match[6]));
  32.         mysql_query("INSERT INTO `abcdef` VALUES ('". mysql_real_escape_string($match[1])."', '". mysql_real_escape_string($match[2])."', '". mysql_real_escape_string($match[3])."', '". mysql_real_escape_string($match[4])."','". mysql_real_escape_string($match[5])."','". mysql_real_escape_string($match[6])."', '".mysql_real_escape_string($region_last)."', '".mysql_real_escape_string($region_first)."')", $mysql);
  33.     }
  34. }
  35. mysql_close($mysql);
  36. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement