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+см)(\/)?(\d+)?(мг|мл|г|доз([аы])?)?(([\w+\W+]{1,})\d*[.,]?\d+(\s|\/)?(мг|мл|гр|г|мкг|ед|тыс\W+ме|тыс\W+ед|тыс|ме|кв\W+см|доз([аы])?)(\/)?(\d+)?(мг|мл|г|доз([аы])?)?)?/ui', $title, $matches)) {
- $unit = $matches[0];
- // if (mb_substr_count($title, 'флуимуцил антибиотик') > 0) {
- // echo 1;
- // }
- }
- if (preg_match('/\s\d*[.,]?\d+(\s)?(\+)(\s)?\d*[.,]?\d+\s/ui', $title, $matches)) {
- $unit = $matches[0];
- }
- if (preg_match('/(\d*[.,]?\d+)(\s)(мг|мл|гр|г|мкг|ед|тыс\W+ме|тыс\W+ед|тыс|ме|кв\W+см)/ui', $title, $matches)) {
- $title = preg_replace('/(\d*[.,]?\d+)(\s)(мг|мл|гр|г|мкг|ед|тыс\W+ме|тыс\W+ед|тыс|ме|кв\W+см)/ui','$1' . '$3', $title);
- }
- $result = [];
- array_push($result, trim($title), trim($unit));
- return $result;
- }
- function getQuantity($title) {
- $quantity = null;
- if (preg_match('/(№|Х|X|N)(\s)?(\s)?\d+((\s)?(№|Х|X|N)\d+)?/ui', $title, $matches)) {
- $quantity = $matches[0];
- // if (mb_substr_count($title, 'ливиал') > 0) {
- // echo 1;
- // }
- if (preg_match('/(Х|X|N)/ui', $title)) {
- $title = preg_replace('/(Х|X|N)/ui','№', $title);
- }
- if (preg_match('/(№)(\s)(\d*[.,]?\d+)/ui', $title)) {
- $title = preg_replace('/(№)(\s)(\d*[.,]?\d+)/ui','$1' . '$3', $title);
- }
- if (preg_match('/(№)(\d*[.,]?\d+)(№)(\d*[.,]?\d+)/ui', $title)) {
- $title = preg_replace('/(№)(\d*[.,]?\d+)(№)(\d*[.,]?\d+)/ui','$1' . '$2' . ' ' . '$3' . '$4', $title);
- }
- }
- $result = [];
- array_push($result, trim($title), trim($quantity));
- return $result;
- }
- $utf_csv = array_map('str_getcsv', file('1.csv'));
- //убираем первый элемент массива - заголовки
- //array_shift($utf_csv);
- $old_titles = [];
- $new_titles = [];
- $drug = [];
- $drugs = [];
- foreach ($utf_csv as $utf_row) {
- $true_title = mb_strtolower($utf_row[1]);
- $b = getUnit($true_title);
- $edit_title = $b[0];
- $unit = $b[1];
- $a = getQuantity($edit_title);
- $edit_title = $a[0];
- $quantity = $a[1];
- $drug = [];
- array_push($drug, $true_title, $unit, $quantity);
- array_push($drugs, $drug);
- unset($a);
- unset($b);
- unset($drug);
- }
- $cut_titles = [];
- foreach ($utf_csv as $i => $utf_row) {
- $true_title = mb_strtolower($utf_row[1]);
- $drug = $drugs[$i];
- $cut_title = str_replace($drug[1], '', $true_title);
- $cut_title = str_replace($drug[2], '', $cut_title);
- if (preg_match('/\d*[,]?\d+[%]/ui', $cut_title, $matches)) {
- $percentage = $matches[0];
- }
- $cut_title = preg_replace('/\s\s/ui',' ', $cut_title);
- array_push($cut_titles, trim($cut_title));
- }
- //общий список слов на удаление
- foreach ($cut_titles as &$cut_title) {
- $cut_title = preg_replace('/(ТУБА)(\/)(МПЗ)(\/)/ui','', $cut_title);
- $cut_title = str_replace('(тубы алюминиевые)', '', $cut_title);
- $cut_title = preg_replace('/(\/)?(бад|блистеры|блистер|флак|фл|туб[аы]|туб)(\/)?(\.)?/ui','', $cut_title);
- $cut_title = preg_replace('/(\()(\))/ui','', $cut_title);
- }
- if (preg_match('/\d*[,]?\d+/ui', $cut_title)) {
- array_push($t, $cut_title);
- }
- $tablets = [];
- $capsules = [];
- $salves = [];
- $gels = [];
- foreach ($cut_titles as $cut_title) {
- if (preg_match('/\b(табл|таб)/ui', $cut_title)) {
- array_push($tablets, $cut_title);
- }
- if (preg_match('/\b(капс)\b/ui', $cut_title)) {
- array_push($capsules, $cut_title);
- }
- if (preg_match('/\b(мазь)\b/ui', $cut_title)) {
- array_push($salves, $cut_title);
- }
- if (preg_match('/\b(гель)\b/ui', $cut_title)) {
- array_push($gels, $cut_title);
- }
- }
- foreach ($tablets as &$tablet) {
- $trash1 = [
- 'П/О/ТАТХИМФАРM',
- 'П/О/ТАТХИМФАРМ',
- 'П/О /ХЕМОФАРМ/',
- 'КИШЕЧНОРАСТВ.',
- 'С КОНТРОЛ ВЫСВ П/О',
- 'С ЗАМЕДЛ. ВЫСВОБ.',
- 'КОНТР. ВЫСВ. П/О ПЛЁН',
- 'КОНТР. ВЫСВ. П/О',
- 'контр.в п/о',
- 'пр.д п/о',
- 'ПРОЛОНГИРОВАННОГО ДЕЙСТВИЯ ПОКРЫТЫЕ ПЛЕНОЧНОЙ П/О',
- 'ПРОЛОНГ П/КИШЕЧ РАСТВ/ОБОЛОЧ/',
- 'ПРОЛОНГ. Д-Я П/О ПЛЕН.',
- 'ПРОЛОНГ. ДЕЙСТВ. ПОКР. ПЛЁН. ОБОЛ.',
- 'ПРОЛОНГ. ДЕЙСТВ. П/О ПЛЁНОЧНОЙ',
- 'ПРОЛОНГ. ДЕЙСТ. П/О ПЛЁН.',
- 'ПРОЛОНГ. ДЕЙСТ. П/О ПЛЕН.',
- 'ПРОЛОНГ П/ПЛЕН/ОБОЛОЧ',
- 'ПРОЛОНГ. ДЕЙСТВ.',
- 'ПРОЛОНГ. Д-Я',
- 'ПРОЛОНГ',
- 'ПОКР. ПЛЕН. ОБОЛ.',
- 'С МОДИФИЦ ВЫСВОБ П/ПЛЕН/ОБОЛОЧ',
- 'С МОДИФ. ВЫСВОБ. П/О ПЛЁН.',
- 'С МОДИФ. ВЫСВОБ.',
- 'С МОДИФ. ВЫСВ.',
- 'модиф.в п/о',
- 'П/О/БЛИСТ',
- 'П/О КИШЕЧНОРАСТВ.',
- 'П/О КИШЕЧНОРАСТ.',
- 'П/О К/Ш РАСТВ.',
- 'П/О КШ/РАСТВ.',
- 'П/О КШ/РАСТ.',
- 'п/о киш.раст. ',
- 'п/о плён. кш/раств.',
- 'П/О ПЛЁНОЧНОЙ',
- 'П/О ПЛЕНОЧН.',
- 'П/О ПЛЁНОЧ.',
- 'П/О ПЛЁН.',
- 'П/О ПЛЁН',
- 'П/О ПЛЕН.',
- 'П/О ПЛЕН',
- 'П/ОБ',
- 'П/О/ОЗОН/',
- 'П/О/ОЗОН',
- 'П/П/О',
- 'П.П.О.',
- 'П/О',
- 'п/пл/об.',
- 'ПОКРЫТЫЕ ПЛЁНОЧНОЙ ОБОЛОЧКОЙ',
- 'ПОКРЫТЫЕ ПЛЕНОЧНОЙ ОБОЛОЧКОЙ',
- 'ПОКРЫТЫЕ ОБОЛОЧКОЙ',
- 'П/ПЛЁН/ОБОЛОЧ/ОЗОН/',
- 'П/ПЛЕН/ОБОЛОЧ/ОЗОН/',
- 'П/ПЛЕН/ОБОЛОЧ/',
- 'П/ПЛЁН/ОБОЛОЧ.',
- 'П/ПЛЁН/ОБОЛОЧ',
- 'П/ПЛЕН/ОБОЛОЧ.',
- 'П/ПЛЕН/ОБОЛОЧ',
- 'П/ПЛЕН ОБОЛОЧ',
- 'П/КИШЕЧ/РАСТВ/САХ/ОБ',
- 'ПОКРЫТЫЕ КИШЕЧНОРАСТВОРИМОЙ ОБОЛОЧКОЙ',
- 'П/КИШЕЧНОРАСТВОРИМ/ОБОЛОЧ',
- 'ЛИОФИЛИЗИРОВАННЫЕ',
- 'ДИСПЕРГ.',
- 'ДИСПЕРГ',
- 'ДИСПЕР',
- 'д/обр. зубн.протезов',
- 'пр.д п/о',
- 'модиф.в п/о',
- 'подъязычные',
- 'ПОДЪЯЗЫЧ',
- 'подъяз',
- '/СЕВЕРНАЯ ЗВЕЗДА/',
- '/ФАРМСТАНДАРТ/',
- '/ФАРМПРОЕКТ/',
- '/ТАТХИМФАРМ/',
- '/ПРАНАФАРМ/',
- 'ПРАНАФАРМ/',
- '/ДАЛЬХИМ/',
- '/БИОКОМ/',
- '/ОЗОН/',
- 'ОЗОН/',
- '/ОЗОН',
- 'ОЗОН',
- 'Д/Р-РА/АВЕКСИМА/',
- 'ЛИНГВ',
- ];
- $tablet = preg_replace('/(таблеток и капсул набор)/ui',' таб. и капс. набор', $tablet);
- $tablet = preg_replace('/\b(таблеток|таблетки|табл|таб. раств|таб)(\.)?\b/ui',' таб.', $tablet);
- $tablet = preg_replace('/(жевательные|жеват|жев)(\.)?/ui',' жев.', $tablet);
- $tablet = preg_replace('/(д)(\/)(\s)?(рассасывания|рассасыв|рассас|расс)(\.)?/ui',' для рассас.', $tablet);
- $tablet = preg_replace('/(\()?(для детей и подростков|для детей|детский|детская|детские)(\))?(\.)?/ui','для детей', $tablet);
- $tablet = preg_replace('/(д)(\/)(детей)(\.)?/ui','для детей', $tablet);
- $tablet = preg_replace('/(\.)(\s)?(\.)/ui','.', $tablet);
- $tablet = preg_replace('/\s\s/ui',' ', $tablet);
- // $tablet = preg_replace('/(\()(скидка)\w+(\))/ui','', $tablet);
- foreach ($trash1 as $value) {
- $value = mb_strtolower($value);
- $tablet = str_replace($value, '', $tablet);
- }
- if (preg_match('/\s\s/ui', $tablet)) {
- $tablet = preg_replace('/\s\s/ui',' ', $tablet);
- }
- // //раствор
- // if (preg_match('/[^а-я](р-р|таблетки|табл.|табл|таб. раств|таб.|таб)/ui', $tablet)) {
- // $tablet = preg_replace('/[^а-я](таблеток|таблетки|табл.|табл|таб. раств|таб.|таб)/ui',' раствор', $tablet);
- // }
- $tablet = trim($tablet);
- $file = 'tablet.csv';
- // file_put_contents($file, $tablet . ";\n", FILE_APPEND);
- if (preg_match('/d*[,]?\d+/ui', $tablet)) {
- file_put_contents($file, $tablet . ";\n", FILE_APPEND);
- }
- }
- foreach ($capsules as &$capsule) {
- $trash2 = [
- 'С МОДИФИЦИРОВАННЫМ ВЫСВОБОЖДЕНИЕМ',
- 'С МОДИФ. ВЫСВОБОЖД.',
- 'С МОДИФ. ВЫСВОБ.',
- 'С МОДИФ ВЫСВОБ',
- 'С МОДИФ.ВЫСВОБ.',
- 'С МОДИФ.ВЫСВОБ',
- 'С МОДИФ. ВЫСВ.',
- 'МОДИФ ВЫСВОБ',
- 'С ПРОЛОНГ ВЫСВОБОЖД',
- 'П/О КШ/РАСТВ.',
- 'КШ/РАСТВ.',
- 'КИШЕЧН/РАСТВ/БЛИСТ/',
- 'П/О КШ/РАСТВ.',
- 'КИШЕЧНОРАСТВОРИМЫЕ',
- 'КИШЕЧНОРАСТВ.',
- 'ПРОЛОНГ. ДЕЙСТВ.',
- 'ПРОЛОНГ.ДЕЙСТВ.',
- 'ПРОЛОНГ',
- 'Д/ПОДКОЖ',
- 'ФЛ',
- '/КАНОНФАРМА/',
- '/ВЕРТЕКС/',
- '/ОЗОН/',
- '/ОЗОН',
- ];
- $capsule = preg_replace('/(таблеток и капсул набор)/ui','таб. и капс. набор', $capsule);
- $capsule = preg_replace('/\b(капсулы|капс)(\.)?\b/ui','капс.', $capsule);
- $capsule = preg_replace('/(жевательные|жеват|жев)(\.)?/ui',' жев.', $capsule);
- $capsule = preg_replace('/(вагин|ваг)(\.)?/ui',' ваг.', $capsule);
- $capsule = preg_replace('/(\()?(для детей и подростков|для детей|детский|детская|детские)(\))?(\.)?/ui','для детей', $capsule);
- $capsule = preg_replace('/(д)(\/)(детей|дет)(\.)?/ui','для детей', $capsule);
- $capsule = preg_replace('/(\.)(\s)?(\.)/ui','.', $capsule);
- $capsule = preg_replace('/\s\s/ui',' ', $capsule);
- $capsule = str_replace('с пор. д/инг.', 'с порошком для инг.', $capsule);
- foreach ($trash2 as $value) {
- $value = mb_strtolower($value);
- $capsule = str_replace($value, '', $capsule);
- }
- $capsule = trim($capsule);
- }
- foreach ($salves as &$salve) {
- $trash3 = [
- '/САМАРАМЕДПРОМ/',
- '/ТАТХИМФАРМ',
- '/БИОХИМИК/',
- '/БИОХИМИК',
- ];
- $salve = preg_replace('/(для|д)?(\/)?(\s)?(наружного|наружн|наруж|нар)(\.)?(\s)?(применения|примен|прим|пр)?(\.)?\b/ui',' для наруж. прим. ', $salve);
- $salve = preg_replace('/(для|д)?(\/)?(\s)?(местного|местн|мест)(\.)?(\s)?(применения|примен|прим|пр)?(\.)?\b/ui',' для местн. прим. ', $salve);
- $salve = str_replace('(в комплекте с наконечниками 4шт.)', '', $salve);
- $salve = preg_replace('/(\.)(\s)?(\.)/ui','.', $salve);
- $salve = preg_replace('/\s\s/ui',' ', $salve);
- foreach ($trash3 as $value) {
- $value = mb_strtolower($value);
- $salve = str_replace($value, '', $salve);
- }
- $salve = trim($salve);
- }
- foreach ($gels as &$gel) {
- $trash4 = [
- ];
- // для местного и наружного
- $gel = preg_replace('/(для|д)?(\/)?(\s)?(наружного|наружн|наруж|нар)(\.)?(\s)?(применения|примен|прим|пр)?(\.)?\b/ui',' для наруж. прим. ', $gel);
- $gel = preg_replace('/(н)[\/|\.](п)/ui',' для наруж. прим.', $gel);
- $gel = preg_replace('/(для|д)?(\/)?(\s)?(местного|местн|мест)(\.)?(\s)?(применения|примен|прим|пр)?(\.)?\b/ui',' для местн. прим. ', $gel);
- $gel = preg_replace('/(\()?(для детей и подростков|для детей|детский|детская|детские)(\))?(\.)?/ui',' для детей ', $gel);
- $gel = str_replace('д/', 'для ', $gel);
- $gel = str_replace('(треуг. крышка)', '', $gel);
- $gel = preg_replace('/(\.)(\s)?(\.)/ui','.', $gel);
- // $gel = preg_replace('/[^а-я][-][^а-я]/ui','-', $gel);
- $gel = preg_replace('/\s\s/ui',' ', $gel);
- foreach ($trash4 as $value) {
- $value = mb_strtolower($value);
- $gel = str_replace($value, '', $gel);
- }
- $gel = trim($gel);
- }
- unset($i);
- unset($trash1);
- unset($trash2);
- unset($trash3);
- unset($tablet);
- unset($capsule);
- unset($salve);
- echo 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement