80 lines
1.7 KiB
PHP
80 lines
1.7 KiB
PHP
|
<?php
|
||
|
|
||
|
require_once('/home/cloud/core/api/php/db.php');
|
||
|
require_once('/home/cloud/core/api/php/json.php');
|
||
|
DB::$type='sqlite3';
|
||
|
DB::$path='/home/cloud/core/bd/tk-ligat.ru.db';
|
||
|
|
||
|
function generate_password($number){
|
||
|
$arr = array('a','b','c','d','e','f', 'g','h','i','j','k','l','m','n','o','p','r','s','t','u','v','x','y','z','1','2','3','4','5','6','7','8','9','0');
|
||
|
$pass = "";
|
||
|
for($i = 0; $i < $number; $i++){
|
||
|
$index = rand(0, count($arr) - 1);
|
||
|
$pass .= $arr[$index];
|
||
|
}
|
||
|
return $pass;
|
||
|
}
|
||
|
|
||
|
|
||
|
function delxml ($text) { // ФУНКЦИЯ очистки кода
|
||
|
$old1 = array('"');#Ищем вредное ">",, "<"
|
||
|
$new1 = array("");#Меняем на полезное">", , "<"
|
||
|
$text = str_replace($old1, $new1, $text);#Собсно сама замена =)
|
||
|
return $text;
|
||
|
}
|
||
|
|
||
|
//$current=file_get_contents('1.csv');
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
$i=0;
|
||
|
$fp = @fopen("12.csv", "r");
|
||
|
if ($fp) {
|
||
|
while (($buffer = fgets($fp, 4096)) !== false) {
|
||
|
// echo $buffer;
|
||
|
$pieces[$i] = explode(";",$buffer);
|
||
|
|
||
|
$i++;
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
}
|
||
|
if (!feof($fp)) {
|
||
|
echo "Ошибка: fgets() неожиданно потерпел неудачу\n";
|
||
|
}
|
||
|
fclose($fp);
|
||
|
}
|
||
|
|
||
|
|
||
|
$res=0;
|
||
|
for ($i=1; $i<count($pieces); $i++){
|
||
|
|
||
|
$txt=trim(delxml($pieces[$i][0]));
|
||
|
$inn=$pieces[$i][1];
|
||
|
$kpp=$pieces[$i][2];
|
||
|
|
||
|
//проверяем существование
|
||
|
$id=DB::getValue("SELECT `id` FROM `org` WHERE `inn`=? AND `kpp`=?", array($inn, $kpp));
|
||
|
if (!$id){
|
||
|
DB::add("INSERT INTO `org` (`txt`, `inn`, `kpp`) VALUES (?, ?, ?)", array($txt, $inn, $kpp));
|
||
|
$res++;
|
||
|
}
|
||
|
|
||
|
unset($txt);
|
||
|
unset($inn);
|
||
|
unset($kpp);
|
||
|
unset($id);
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
echo 'Добавлено: ' . $res . "\n";
|
||
|
//print_r($pieces);
|
||
|
|
||
|
//$data = str_getcsv($current, ';');
|
||
|
//rint_r($data);
|
||
|
|
||
|
|
||
|
?>
|