Advertisement
Guest User

Untitled

a guest
Jan 21st, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 13.77 KB | None | 0 0
  1. <?php
  2.  
  3. function getUnit($title) {
  4.     $unit = null;
  5.  
  6.     if (preg_match('/\d*[.,]?\d+(\s|\/)?(мг|мл|гр|г|мкг|ед|тыс\W+ме|тыс\W+ед|тыс|ме|ле|кв\W+см)(\/)?(\d+)?(мг|мл|г|доз([аы])?)?(([\w+\W+]{1,})\d*[.,]?\d+(\s|\/)?(мг|мл|гр|г|мкг|ед|тыс\W+ме|тыс\W+ед|тыс|ме|кв\W+см|доз([аы])?)(\/)?(\d+)?(мг|мл|г|доз([аы])?)?)?/ui', $title, $matches)) {
  7.         $unit = $matches[0];
  8.  
  9. //        if (mb_substr_count($title, 'флуимуцил антибиотик') > 0) {
  10. //            echo 1;
  11. //        }
  12.     }
  13.  
  14.     if (preg_match('/\s\d*[.,]?\d+(\s)?(\+)(\s)?\d*[.,]?\d+\s/ui', $title, $matches)) {
  15.         $unit = $matches[0];
  16.     }
  17.  
  18.     if (preg_match('/(\d*[.,]?\d+)(\s)(мг|мл|гр|г|мкг|ед|тыс\W+ме|тыс\W+ед|тыс|ме|кв\W+см)/ui', $title, $matches)) {
  19.         $title = preg_replace('/(\d*[.,]?\d+)(\s)(мг|мл|гр|г|мкг|ед|тыс\W+ме|тыс\W+ед|тыс|ме|кв\W+см)/ui','$1' . '$3', $title);
  20.     }
  21.  
  22.     $result = [];
  23.  
  24.     array_push($result, trim($title), trim($unit));
  25.  
  26.     return $result;
  27. }
  28.  
  29. function getQuantity($title) {
  30.     $quantity = null;
  31.  
  32.     if (preg_match('/(№|Х|X|N)(\s)?(\s)?\d+((\s)?(№|Х|X|N)\d+)?/ui', $title, $matches)) {
  33.  
  34.         $quantity = $matches[0];
  35.  
  36. //        if (mb_substr_count($title, 'ливиал') > 0) {
  37. //            echo 1;
  38. //        }
  39.  
  40.         if (preg_match('/(Х|X|N)/ui', $title)) {
  41.             $title = preg_replace('/(Х|X|N)/ui','№', $title);
  42.         }
  43.  
  44.         if (preg_match('/(№)(\s)(\d*[.,]?\d+)/ui', $title)) {
  45.             $title = preg_replace('/(№)(\s)(\d*[.,]?\d+)/ui','$1' . '$3', $title);
  46.         }
  47.  
  48.         if (preg_match('/(№)(\d*[.,]?\d+)(№)(\d*[.,]?\d+)/ui', $title)) {
  49.             $title = preg_replace('/(№)(\d*[.,]?\d+)(№)(\d*[.,]?\d+)/ui','$1' . '$2' . ' ' . '$3' . '$4', $title);
  50.         }
  51.     }
  52.  
  53.     $result = [];
  54.  
  55.     array_push($result, trim($title), trim($quantity));
  56.  
  57.     return $result;
  58. }
  59.  
  60. $utf_csv = array_map('str_getcsv', file('1.csv'));
  61.  
  62. //убираем первый элемент массива - заголовки
  63. //array_shift($utf_csv);
  64.  
  65. $old_titles = [];
  66. $new_titles = [];
  67.  
  68. $drug = [];
  69. $drugs = [];
  70.  
  71. foreach ($utf_csv as $utf_row) {
  72.     $true_title = mb_strtolower($utf_row[1]);
  73.  
  74.     $b = getUnit($true_title);
  75.  
  76.     $edit_title = $b[0];
  77.     $unit = $b[1];
  78.  
  79.     $a = getQuantity($edit_title);
  80.  
  81.     $edit_title = $a[0];
  82.     $quantity = $a[1];
  83.  
  84.     $drug = [];
  85.  
  86.     array_push($drug, $true_title, $unit, $quantity);
  87.     array_push($drugs, $drug);
  88.  
  89.     unset($a);
  90.     unset($b);
  91.     unset($drug);
  92. }
  93.  
  94. $cut_titles = [];
  95.  
  96. foreach ($utf_csv as $i => $utf_row) {
  97.     $true_title = mb_strtolower($utf_row[1]);
  98.  
  99.     $drug = $drugs[$i];
  100.  
  101.     $cut_title = str_replace($drug[1], '', $true_title);
  102.     $cut_title = str_replace($drug[2], '', $cut_title);
  103.  
  104.     if (preg_match('/\d*[,]?\d+[%]/ui', $cut_title, $matches)) {
  105.         $percentage = $matches[0];
  106.     }
  107.  
  108.     $cut_title = preg_replace('/\s\s/ui',' ', $cut_title);
  109.  
  110.     array_push($cut_titles, trim($cut_title));
  111. }
  112.  
  113. //общий список слов на удаление
  114. foreach ($cut_titles as &$cut_title) {
  115.     $cut_title = preg_replace('/(ТУБА)(\/)(МПЗ)(\/)/ui','', $cut_title);
  116.  
  117.     $cut_title = str_replace('(тубы алюминиевые)', '', $cut_title);
  118.  
  119.     $cut_title = preg_replace('/(\/)?(бад|блистеры|блистер|флак|фл|туб[аы]|туб)(\/)?(\.)?/ui','', $cut_title);
  120.  
  121.     $cut_title = preg_replace('/(\()(\))/ui','', $cut_title);
  122.  
  123. }
  124.  
  125. if (preg_match('/\d*[,]?\d+/ui', $cut_title)) {
  126.     array_push($t, $cut_title);
  127. }
  128.  
  129. $tablets = [];
  130.  
  131. $capsules = [];
  132.  
  133. $salves = [];
  134.  
  135. $gels = [];
  136.  
  137. foreach ($cut_titles as $cut_title) {
  138.  
  139.     if (preg_match('/\b(табл|таб)/ui', $cut_title)) {
  140.         array_push($tablets, $cut_title);
  141.     }
  142.  
  143.     if (preg_match('/\b(капс)\b/ui', $cut_title)) {
  144.         array_push($capsules, $cut_title);
  145.     }
  146.  
  147.     if (preg_match('/\b(мазь)\b/ui', $cut_title)) {
  148.         array_push($salves, $cut_title);
  149.     }
  150.  
  151.     if (preg_match('/\b(гель)\b/ui', $cut_title)) {
  152.         array_push($gels, $cut_title);
  153.     }
  154. }
  155.  
  156. foreach ($tablets as &$tablet) {
  157.  
  158.     $trash1 = [
  159.         'П/О/ТАТХИМФАРM',
  160.         'П/О/ТАТХИМФАРМ',
  161.         'П/О /ХЕМОФАРМ/',
  162.         'КИШЕЧНОРАСТВ.',
  163.         'С КОНТРОЛ ВЫСВ П/О',
  164.         'С ЗАМЕДЛ. ВЫСВОБ.',
  165.         'КОНТР. ВЫСВ. П/О ПЛЁН',
  166.         'КОНТР. ВЫСВ. П/О',
  167.         'контр.в п/о',
  168.         'пр.д п/о',
  169.         'ПРОЛОНГИРОВАННОГО ДЕЙСТВИЯ ПОКРЫТЫЕ ПЛЕНОЧНОЙ П/О',
  170.         'ПРОЛОНГ П/КИШЕЧ РАСТВ/ОБОЛОЧ/',
  171.         'ПРОЛОНГ. Д-Я П/О ПЛЕН.',
  172.         'ПРОЛОНГ. ДЕЙСТВ. ПОКР. ПЛЁН. ОБОЛ.',
  173.         'ПРОЛОНГ. ДЕЙСТВ. П/О ПЛЁНОЧНОЙ',
  174.         'ПРОЛОНГ. ДЕЙСТ. П/О ПЛЁН.',
  175.         'ПРОЛОНГ. ДЕЙСТ. П/О ПЛЕН.',
  176.         'ПРОЛОНГ П/ПЛЕН/ОБОЛОЧ',
  177.         'ПРОЛОНГ. ДЕЙСТВ.',
  178.         'ПРОЛОНГ. Д-Я',
  179.         'ПРОЛОНГ',
  180.         'ПОКР. ПЛЕН. ОБОЛ.',
  181.         'С МОДИФИЦ ВЫСВОБ П/ПЛЕН/ОБОЛОЧ',
  182.         'С МОДИФ. ВЫСВОБ. П/О ПЛЁН.',
  183.         'С МОДИФ. ВЫСВОБ.',
  184.         'С МОДИФ. ВЫСВ.',
  185.         'модиф.в п/о',
  186.         'П/О/БЛИСТ',
  187.         'П/О КИШЕЧНОРАСТВ.',
  188.         'П/О КИШЕЧНОРАСТ.',
  189.         'П/О К/Ш РАСТВ.',
  190.         'П/О КШ/РАСТВ.',
  191.         'П/О КШ/РАСТ.',
  192.         'п/о киш.раст. ',
  193.         'п/о плён. кш/раств.',
  194.         'П/О ПЛЁНОЧНОЙ',
  195.         'П/О ПЛЕНОЧН.',
  196.         'П/О ПЛЁНОЧ.',
  197.         'П/О ПЛЁН.',
  198.         'П/О ПЛЁН',
  199.         'П/О ПЛЕН.',
  200.         'П/О ПЛЕН',
  201.         'П/ОБ',
  202.         'П/О/ОЗОН/',
  203.         'П/О/ОЗОН',
  204.         'П/П/О',
  205.         'П.П.О.',
  206.         'П/О',
  207.         'п/пл/об.',
  208.         'ПОКРЫТЫЕ ПЛЁНОЧНОЙ ОБОЛОЧКОЙ',
  209.         'ПОКРЫТЫЕ ПЛЕНОЧНОЙ ОБОЛОЧКОЙ',
  210.         'ПОКРЫТЫЕ ОБОЛОЧКОЙ',
  211.         'П/ПЛЁН/ОБОЛОЧ/ОЗОН/',
  212.         'П/ПЛЕН/ОБОЛОЧ/ОЗОН/',
  213.         'П/ПЛЕН/ОБОЛОЧ/',
  214.         'П/ПЛЁН/ОБОЛОЧ.',
  215.         'П/ПЛЁН/ОБОЛОЧ',
  216.         'П/ПЛЕН/ОБОЛОЧ.',
  217.         'П/ПЛЕН/ОБОЛОЧ',
  218.         'П/ПЛЕН ОБОЛОЧ',
  219.         'П/КИШЕЧ/РАСТВ/САХ/ОБ',
  220.         'ПОКРЫТЫЕ КИШЕЧНОРАСТВОРИМОЙ ОБОЛОЧКОЙ',
  221.         'П/КИШЕЧНОРАСТВОРИМ/ОБОЛОЧ',
  222.         'ЛИОФИЛИЗИРОВАННЫЕ',
  223.         'ДИСПЕРГ.',
  224.         'ДИСПЕРГ',
  225.         'ДИСПЕР',
  226.         'д/обр. зубн.протезов',
  227.         'пр.д п/о',
  228.         'модиф.в п/о',
  229.         'подъязычные',
  230.         'ПОДЪЯЗЫЧ',
  231.         'подъяз',
  232.         '/СЕВЕРНАЯ ЗВЕЗДА/',
  233.         '/ФАРМСТАНДАРТ/',
  234.         '/ФАРМПРОЕКТ/',
  235.         '/ТАТХИМФАРМ/',
  236.         '/ПРАНАФАРМ/',
  237.         'ПРАНАФАРМ/',
  238.         '/ДАЛЬХИМ/',
  239.         '/БИОКОМ/',
  240.         '/ОЗОН/',
  241.         'ОЗОН/',
  242.         '/ОЗОН',
  243.         'ОЗОН',
  244.         'Д/Р-РА/АВЕКСИМА/',
  245.         'ЛИНГВ',
  246.     ];
  247.  
  248.     $tablet = preg_replace('/(таблеток и капсул набор)/ui',' таб. и капс. набор', $tablet);
  249.  
  250.     $tablet = preg_replace('/\b(таблеток|таблетки|табл|таб. раств|таб)(\.)?\b/ui',' таб.', $tablet);
  251.  
  252.     $tablet = preg_replace('/(жевательные|жеват|жев)(\.)?/ui',' жев.', $tablet);
  253.  
  254.     $tablet = preg_replace('/(д)(\/)(\s)?(рассасывания|рассасыв|рассас|расс)(\.)?/ui',' для рассас.', $tablet);
  255.  
  256.     $tablet = preg_replace('/(\()?(для детей и подростков|для детей|детский|детская|детские)(\))?(\.)?/ui','для детей', $tablet);
  257.  
  258.     $tablet = preg_replace('/(д)(\/)(детей)(\.)?/ui','для детей', $tablet);
  259.  
  260.     $tablet = preg_replace('/(\.)(\s)?(\.)/ui','.', $tablet);
  261.  
  262.     $tablet = preg_replace('/\s\s/ui',' ', $tablet);
  263.  
  264. //    $tablet = preg_replace('/(\()(скидка)\w+(\))/ui','', $tablet);
  265.  
  266.     foreach ($trash1 as $value) {
  267.         $value = mb_strtolower($value);
  268.         $tablet = str_replace($value, '', $tablet);
  269.     }
  270.  
  271.     if (preg_match('/\s\s/ui', $tablet)) {
  272.         $tablet = preg_replace('/\s\s/ui',' ', $tablet);
  273.     }
  274.  
  275. //    //раствор
  276. //    if (preg_match('/[^а-я](р-р|таблетки|табл.|табл|таб. раств|таб.|таб)/ui', $tablet)) {
  277. //        $tablet = preg_replace('/[^а-я](таблеток|таблетки|табл.|табл|таб. раств|таб.|таб)/ui',' раствор', $tablet);
  278. //    }
  279.  
  280.     $tablet = trim($tablet);
  281.  
  282.     $file = 'tablet.csv';
  283. //    file_put_contents($file, $tablet . ";\n", FILE_APPEND);
  284.  
  285.     if (preg_match('/d*[,]?\d+/ui', $tablet)) {
  286.         file_put_contents($file, $tablet . ";\n", FILE_APPEND);
  287.     }
  288.  
  289.  
  290. }
  291.  
  292. foreach ($capsules as &$capsule) {
  293.     $trash2 = [
  294.         'С МОДИФИЦИРОВАННЫМ ВЫСВОБОЖДЕНИЕМ',
  295.         'С МОДИФ. ВЫСВОБОЖД.',
  296.         'С МОДИФ. ВЫСВОБ.',
  297.         'С МОДИФ ВЫСВОБ',
  298.         'С МОДИФ.ВЫСВОБ.',
  299.         'С МОДИФ.ВЫСВОБ',
  300.         'С МОДИФ. ВЫСВ.',
  301.         'МОДИФ ВЫСВОБ',
  302.         'С ПРОЛОНГ ВЫСВОБОЖД',
  303.         'П/О КШ/РАСТВ.',
  304.         'КШ/РАСТВ.',
  305.         'КИШЕЧН/РАСТВ/БЛИСТ/',
  306.         'П/О КШ/РАСТВ.',
  307.         'КИШЕЧНОРАСТВОРИМЫЕ',
  308.         'КИШЕЧНОРАСТВ.',
  309.         'ПРОЛОНГ. ДЕЙСТВ.',
  310.         'ПРОЛОНГ.ДЕЙСТВ.',
  311.         'ПРОЛОНГ',
  312.         'Д/ПОДКОЖ',
  313.         'ФЛ',
  314.         '/КАНОНФАРМА/',
  315.         '/ВЕРТЕКС/',
  316.         '/ОЗОН/',
  317.         '/ОЗОН',
  318.     ];
  319.  
  320.     $capsule = preg_replace('/(таблеток и капсул набор)/ui','таб. и капс. набор', $capsule);
  321.  
  322.     $capsule = preg_replace('/\b(капсулы|капс)(\.)?\b/ui','капс.', $capsule);
  323.  
  324.     $capsule = preg_replace('/(жевательные|жеват|жев)(\.)?/ui',' жев.', $capsule);
  325.  
  326.     $capsule = preg_replace('/(вагин|ваг)(\.)?/ui',' ваг.', $capsule);
  327.  
  328.     $capsule = preg_replace('/(\()?(для детей и подростков|для детей|детский|детская|детские)(\))?(\.)?/ui','для детей', $capsule);
  329.  
  330.     $capsule = preg_replace('/(д)(\/)(детей|дет)(\.)?/ui','для детей', $capsule);
  331.  
  332.     $capsule = preg_replace('/(\.)(\s)?(\.)/ui','.', $capsule);
  333.  
  334.     $capsule = preg_replace('/\s\s/ui',' ', $capsule);
  335.  
  336.     $capsule = str_replace('с пор. д/инг.', 'с порошком для инг.', $capsule);
  337.  
  338.     foreach ($trash2 as $value) {
  339.         $value = mb_strtolower($value);
  340.         $capsule = str_replace($value, '', $capsule);
  341.     }
  342.  
  343.     $capsule = trim($capsule);
  344. }
  345.  
  346. foreach ($salves as &$salve) {
  347.     $trash3 = [
  348.         '/САМАРАМЕДПРОМ/',
  349.         '/ТАТХИМФАРМ',
  350.         '/БИОХИМИК/',
  351.         '/БИОХИМИК',
  352.     ];
  353.  
  354.     $salve = preg_replace('/(для|д)?(\/)?(\s)?(наружного|наружн|наруж|нар)(\.)?(\s)?(применения|примен|прим|пр)?(\.)?\b/ui',' для наруж. прим. ', $salve);
  355.  
  356.     $salve = preg_replace('/(для|д)?(\/)?(\s)?(местного|местн|мест)(\.)?(\s)?(применения|примен|прим|пр)?(\.)?\b/ui',' для местн. прим. ', $salve);
  357.  
  358.     $salve = str_replace('(в комплекте с наконечниками 4шт.)', '', $salve);
  359.  
  360.     $salve = preg_replace('/(\.)(\s)?(\.)/ui','.', $salve);
  361.  
  362.     $salve = preg_replace('/\s\s/ui',' ', $salve);
  363.  
  364.     foreach ($trash3 as $value) {
  365.         $value = mb_strtolower($value);
  366.         $salve = str_replace($value, '', $salve);
  367.     }
  368.  
  369.     $salve = trim($salve);
  370. }
  371.  
  372. foreach ($gels as &$gel) {
  373.     $trash4 = [
  374.     ];
  375.  
  376.     // для местного и наружного
  377.  
  378.     $gel = preg_replace('/(для|д)?(\/)?(\s)?(наружного|наружн|наруж|нар)(\.)?(\s)?(применения|примен|прим|пр)?(\.)?\b/ui',' для наруж. прим. ', $gel);
  379.  
  380.     $gel = preg_replace('/(н)[\/|\.](п)/ui',' для наруж. прим.', $gel);
  381.  
  382.     $gel = preg_replace('/(для|д)?(\/)?(\s)?(местного|местн|мест)(\.)?(\s)?(применения|примен|прим|пр)?(\.)?\b/ui',' для местн. прим. ', $gel);
  383.  
  384.     $gel = preg_replace('/(\()?(для детей и подростков|для детей|детский|детская|детские)(\))?(\.)?/ui',' для детей ', $gel);
  385.  
  386.     $gel = str_replace('д/', 'для ', $gel);
  387.  
  388.     $gel = str_replace('(треуг. крышка)', '', $gel);
  389.  
  390.     $gel = preg_replace('/(\.)(\s)?(\.)/ui','.', $gel);
  391.  
  392. //    $gel = preg_replace('/[^а-я][-][^а-я]/ui','-', $gel);
  393.  
  394.     $gel = preg_replace('/\s\s/ui',' ', $gel);
  395.  
  396.     foreach ($trash4 as $value) {
  397.         $value = mb_strtolower($value);
  398.         $gel = str_replace($value, '', $gel);
  399.     }
  400.  
  401.     $gel = trim($gel);
  402. }
  403.  
  404. unset($i);
  405. unset($trash1);
  406. unset($trash2);
  407. unset($trash3);
  408. unset($tablet);
  409. unset($capsule);
  410. unset($salve);
  411.  
  412. echo 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement