Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $config['mysql_host'] = 'localhost';
- $config['mysql_user'] = 'user';
- $config['mysql_password'] = 'password';
- $config['mysql_base'] = 'db';
- $mysql = mysql_connect($config['mysql_host'],$config['mysql_user'],$config['mysql_password']);
- mysql_select_db($config['mysql_base'], $mysql);
- mysql_query("SET NAMES 'utf8'", $mysql);
- mysql_query("TRUNCATE TABLE `abcdef`", $mysql);
- $filename=array(
- 'DEF-9x.html',
- 'ABC-3x.html',
- 'ABC-4x.html',
- 'ABC-8x.html'
- );
- $re='@<tr><td>(\d+)</td><td>(\d+)</td><td>(\d+)</td><td>(\d+)</td><td>(.+)</td><td>(.+)</td></tr>@umx';
- foreach ($filename as $fn){
- print($fn."\n");
- $txt = file_get_contents($fn);
- $txt = iconv ('cp1251','utf8',$txt);
- $txt=str_replace("\t",'',$txt);
- preg_match_all($re,$txt,$result,PREG_SET_ORDER);
- foreach ($result as $match){
- $region_last = trim(preg_replace("/.*\|/Uu", "", $match[6]));
- $region_first = trim(preg_replace("/\|(.*)$/Uu", "", $match[6]));
- 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);
- }
- }
- mysql_close($mysql);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment