Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function getUnit($title) {
- $unit = null;
- 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)) {
- $unit = $matches[0];
- if (mb_substr_count($title, 'гель') > 0) {
- echo 1;
- }
- }
- if (preg_match('/№\d+/ui', $unit)) {
- $unit = preg_replace('/№\d+/ui', '', $unit);
- }
- if (preg_match('/(\(|\))/ui', $unit)) {
- $unit = preg_replace('/(\(|\))/ui', '', $unit);
- }
- if ($unit != null) {
- $a = substr($unit, 0, 1);
- $b = substr($unit, 1);
- if ($a == '.') {
- $unit = $b;
- }
- }
- return trim($unit);
- }
- function getQuantity($title) {
- $quantity = null;
- if (preg_match('/(№|х|x|N)(\s)?\d+((\s)?(№|х|x|N)\d+)?/ui', $title, $matches)) {
- $quantity = $matches[0];
- if (preg_match('/(№|х|x|N)/ui', $quantity)) {
- $quantity = preg_replace('/(№|х|x|N)/ui','№', $quantity);
- }
- if (preg_match('/\s/ui', $quantity)) {
- $quantity = preg_replace('/\s/ui','', $quantity);
- }
- if (preg_match('/\s\s/ui', $quantity)) {
- $quantity = preg_replace('/\s\s/ui',' ', $quantity);
- }
- $quantity = preg_replace('/№/ui',' №', $quantity);
- }
- return trim($quantity);
- }
- $utf_csv = array_map('str_getcsv', file('unloading.csv'));
- //убираем первый элемент массива - заголовки
- array_shift($utf_csv);
- $old_titles = [];
- $new_titles = [];
- $drug = [];
- $drugs = [];
- foreach ($utf_csv as $utf_row) {
- $true_title = mb_strtolower($utf_row[1]);
- $quantity = '';
- $grammar = '';
- // if (preg_match('/(таб)(\.)?/ui', $true_title)) {
- // $file = 'tablet.csv';
- // file_put_contents($file, $true_title . ";\n", FILE_APPEND);
- // }
- //
- // if (preg_match('/(КАПС)(\.)?/ui', $true_title)) {
- // $file = 'cupsuls.csv';
- // file_put_contents($file, $true_title . ";\n", FILE_APPEND);
- // }
- //
- // if (preg_match('/(Р-Р)(\.)?/ui', $true_title)) {
- // $file = 'растворы.csv';
- // file_put_contents($file, $true_title . ";\n", FILE_APPEND);
- // }
- //
- // if (preg_match('/(КАПС)(\.)?/ui', $true_title)) {
- // $file = 'cupsuls.csv';
- // file_put_contents($file, $true_title . ";\n", FILE_APPEND);
- // }
- $unit = getUnit($true_title);
- $quantity = getQuantity($true_title);
- array_push($drug, $true_title, $unit, $quantity);
- // array_push($drug, $unit, $quantity);
- // if (preg_match('/(№|х|x|N)(\s)?\d+((\s)?(№|х|x|N)\d+)?/ui', $true_title, $matches)) {
- // if (preg_match('/(№|х|x|N)(\s)?\d+((\s)?(№|х|x|N)\d+)?/ui', $matches[0])) {
- // $quantity = preg_replace('/(№|х|x|N)/ui','№', $matches[0]);
- //
- // if (preg_match('/(№|х|x|N)\s\d+/ui', $quantity)) {
- // $quantity = preg_replace('/(№|х|x|N)(\s)/ui','№', $quantity);
- // }
- //
- // if (preg_match('/\d+\№/ui', $quantity)) {
- // $quantity = preg_replace('/\№\d+/ui','$0 ', $quantity);
- // }
- // }
- //
- // $quantity = trim($quantity);
- // }
- //
- // if (preg_match('/\d*(\.|\,)?\d+(\s)?(\/)?(мг|мл|гр|г|мкг|ед)((\+)?(\s)?(\d+)?\d*(\.|\,)?\d+(\s)?(мг|мл|гр|г|мкг|ед))?/ui', $true_title, $matches)) {
- // if (preg_match('/(\s)?/ui', $matches[0])) {
- // $grammar = preg_replace('/(\s)?/ui','', $matches[0]);
- // }
- //
- // if (preg_match('/(мг|мл|гр|г|мкг|ед)\d*/ui', $matches[0])) {
- // $grammar = preg_replace('/\d*(\.|\,)\d+(мг|мл|гр|г|мкг|ед)/ui','$0 ', $matches[0]);
- // }
- //
- // if (preg_match('/\//ui', $matches[0])) {
- // $grammar = preg_replace('/\//ui','', $matches[0]);
- // }
- //
- // $grammar = trim($grammar);
- // }
- // $drug = [];
- // array_push($drug, $true_title, $quantity, $grammar);
- // array_push($drugs, $drug);
- // if ($true_title === replace($true_title)) {
- // array_push($old_titles, $true_title);
- // } else {
- // array_push($new_titles, replace($true_title));
- // }
- }
- echo 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement