Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.51 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+см)\W(\d+)?(мг|мл|г|доз([аы])?)?((\s)?(\+)?([\w+\W+]{1,})(\s)?\d*[.,]?\d+(\s|\/)?(мг|мл|гр|г|мкг|ед|тыс\W+ме|тыс\W+ед|тыс|ме|кв\W+см|доз([аы])?)\W)?/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('/№\d+/ui', $unit)) {
  15.         $unit = preg_replace('/№\d+/ui', '', $unit);
  16.     }
  17.  
  18.     if (preg_match('/(\(|\))/ui', $unit)) {
  19.         $unit = preg_replace('/(\(|\))/ui', '', $unit);
  20.     }
  21.  
  22.     if ($unit != null) {
  23.         $a = substr($unit, 0, 1);
  24.         $b = substr($unit, 1);
  25.  
  26.         if ($a == '.') {
  27.             $unit = $b;
  28.         }
  29.     }
  30.  
  31.     return trim($unit);
  32. }
  33.  
  34. function getQuantity($title) {
  35.     $quantity = null;
  36.  
  37.     if (preg_match('/(№|х|x|N)(\s)?\d+((\s)?(№|х|x|N)\d+)?/ui', $title, $matches)) {
  38.  
  39.         $quantity = $matches[0];
  40.  
  41.         if (preg_match('/(№|х|x|N)/ui', $quantity)) {
  42.             $quantity = preg_replace('/(№|х|x|N)/ui','№', $quantity);
  43.         }
  44.  
  45.         if (preg_match('/\s/ui', $quantity)) {
  46.             $quantity = preg_replace('/\s/ui','', $quantity);
  47.         }
  48.  
  49.         if (preg_match('/\s\s/ui', $quantity)) {
  50.             $quantity = preg_replace('/\s\s/ui',' ', $quantity);
  51.         }
  52.  
  53.         $quantity = preg_replace('/№/ui',' №', $quantity);
  54.     }
  55.  
  56.     return trim($quantity);
  57. }
  58.  
  59. $utf_csv = array_map('str_getcsv', file('unloading.csv'));
  60.  
  61. //убираем первый элемент массива - заголовки
  62. array_shift($utf_csv);
  63.  
  64. $old_titles = [];
  65. $new_titles = [];
  66.  
  67. $drug = [];
  68. $drugs = [];
  69.  
  70. foreach ($utf_csv as $utf_row) {
  71.     $true_title = mb_strtolower($utf_row[1]);
  72.  
  73.     $quantity = '';
  74.  
  75.     $grammar = '';
  76.  
  77. //    if (preg_match('/(таб)(\.)?/ui', $true_title)) {
  78. //        $file = 'tablet.csv';
  79. //        file_put_contents($file, $true_title . ";\n", FILE_APPEND);
  80. //    }
  81. //
  82. //    if (preg_match('/(КАПС)(\.)?/ui', $true_title)) {
  83. //        $file = 'cupsuls.csv';
  84. //        file_put_contents($file, $true_title . ";\n", FILE_APPEND);
  85. //    }
  86. //
  87. //    if (preg_match('/(Р-Р)(\.)?/ui', $true_title)) {
  88. //        $file = 'растворы.csv';
  89. //        file_put_contents($file, $true_title . ";\n", FILE_APPEND);
  90. //    }
  91. //
  92. //    if (preg_match('/(КАПС)(\.)?/ui', $true_title)) {
  93. //        $file = 'cupsuls.csv';
  94. //        file_put_contents($file, $true_title . ";\n", FILE_APPEND);
  95. //    }
  96.  
  97.     $unit = getUnit($true_title);
  98.     $quantity = getQuantity($true_title);
  99.  
  100.     array_push($drug, $true_title, $unit, $quantity);
  101. //    array_push($drug, $unit, $quantity);
  102.  
  103. //    if (preg_match('/(№|х|x|N)(\s)?\d+((\s)?(№|х|x|N)\d+)?/ui', $true_title, $matches)) {
  104. //        if (preg_match('/(№|х|x|N)(\s)?\d+((\s)?(№|х|x|N)\d+)?/ui', $matches[0])) {
  105. //            $quantity = preg_replace('/(№|х|x|N)/ui','№', $matches[0]);
  106. //
  107. //            if (preg_match('/(№|х|x|N)\s\d+/ui', $quantity)) {
  108. //                $quantity = preg_replace('/(№|х|x|N)(\s)/ui','№', $quantity);
  109. //            }
  110. //
  111. //            if (preg_match('/\d+\№/ui', $quantity)) {
  112. //                $quantity = preg_replace('/\№\d+/ui','$0 ', $quantity);
  113. //            }
  114. //        }
  115. //
  116. //        $quantity = trim($quantity);
  117. //    }
  118. //
  119. //    if (preg_match('/\d*(\.|\,)?\d+(\s)?(\/)?(мг|мл|гр|г|мкг|ед)((\+)?(\s)?(\d+)?\d*(\.|\,)?\d+(\s)?(мг|мл|гр|г|мкг|ед))?/ui', $true_title, $matches)) {
  120. //        if (preg_match('/(\s)?/ui', $matches[0])) {
  121. //            $grammar = preg_replace('/(\s)?/ui','', $matches[0]);
  122. //        }
  123. //
  124. //        if (preg_match('/(мг|мл|гр|г|мкг|ед)\d*/ui', $matches[0])) {
  125. //            $grammar = preg_replace('/\d*(\.|\,)\d+(мг|мл|гр|г|мкг|ед)/ui','$0 ', $matches[0]);
  126. //        }
  127. //
  128. //        if (preg_match('/\//ui', $matches[0])) {
  129. //            $grammar = preg_replace('/\//ui','', $matches[0]);
  130. //        }
  131. //
  132. //        $grammar = trim($grammar);
  133. //    }
  134.  
  135. //    $drug = [];
  136.  
  137. //    array_push($drug, $true_title, $quantity, $grammar);
  138.  
  139. //    array_push($drugs, $drug);
  140.  
  141. //    if ($true_title === replace($true_title)) {
  142. //        array_push($old_titles, $true_title);
  143. //    } else {
  144. //        array_push($new_titles, replace($true_title));
  145. //    }
  146.  
  147.  
  148. }
  149.  
  150. echo 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement