In the description of the goods store there is a bunch of html garbage. There are descriptions of this type

<ul> <li><span class="Apple-style-span" style="font-family: Arial, serif; font-size: 12px; ">Кухонные весы</span></li> <li><span class="Apple-style-span" style="font-family: Arial, serif; font-size: 12px; ">Максимальный вес<span class="Apple-tab-span" style="white-space: pre; "> </span>5 кг</span></li> <li><span class="Apple-style-span" style="font-family: Arial, serif; font-size: 12px; ">Цена деления<span class="Apple-tab-span" style="white-space: pre; "> </span>50 г</span></li> <li><span class="Apple-style-span" style="font-family: Arial, serif; font-size: 12px; ">Вес брутто<span class="Apple-tab-span" style="white-space: pre; "> </span>0,6 кг</span></li> <li><span class="Apple-style-span" style="font-family: Arial, serif; font-size: 12px; ">Вес нетто<span class="Apple-tab-span" style="white-space: pre; "> </span>0,34 кг</span></li> <li><span class="Apple-style-span" style="font-family: Arial, serif; font-size: 12px; ">Габариты короба (Д/Ш/Г) 74х18,8х18,8 см</span></li> <li><span class="Apple-style-span" style="font-family: Arial, serif; font-size: 12px; ">Характеристики кухонных весов</span></li> <li><span class="Apple-style-span" style="font-family: Arial, serif; font-size: 12px; ">Легко моющаяся съёмная чаша</span></li> <li><span class="Apple-style-span" style="font-family: Arial, serif; font-size: 12px; ">Ручная регулировка и установка нуля</span></li> </ul> 

and this kind

 <div> <ul> <li>3 в 1: Блендер, Миксер, Измельчитель</li> <li>Погружной блендер из нержавеющей стали</li> <li>Венчики для взбивания яиц и крема</li> <li>Чаша измельчителя</li> <li>2 скоростных режима</li> <li>Настенный держатель</li> <li>Мерный стаканчик</li> <li>Мощность: 700 Вт</li> </ul> </div> 

And this is not all the happiness that I get.

I need to clear this description from html, saving the lines, that is, then to show the user like this:

  • Kitchen Scale Maximum Weight 5
  • Graduation price 50 g
  • Item List
  • Gross weight 0.6 kg
  • Item List
  • Item List

I do this: preg_match_all("|<[^>]+>(.*)</[^>]+>|U",$mytext,$out, PREG_PATTERN_ORDER);

But spans, etc. are not cleaned. Help please write the correct regulars.

    2 answers 2

     <? $content = $arResult['DETAIL_TEXT']; $content = explode('###', strip_tags(str_replace('<li>', '###', $content))); // 1) заменяем все <li>(или любой другой 100% существующий тег) // на ###(или любую отсутствующую последовательность символов); // 2) делаем strip_tags (остается "test1###test2###test3"); // 3) разбиваем строку по разделителю ### // окей, разбиваем по столбцам =) foreach ($content as $n => $str) if (!trim($str)) unset($content[$n]); $out = array(array(), array()); $count2 = floor(count($content)/2); $n = 0; foreach ($content as $str) { $out[intval($n>$count2)][] = trim($str); $n++; } // var_dump($out); // 0 - первый стоблец, 1 - второй. echo '<ul>'; echo '<li><h4>Первый столбец</h4></li>'; foreach($out[0] as $str) echo '<li>'.$str.'</li>'; echo '</ul>'; echo '<ul>'; echo '<li><h4>Второй столбец</h4></li>'; foreach($out[1] as $str) echo '<li>'.$str.'</li>'; echo '</ul>'; ?> 
    • Sorry, I did not really understand what it does. It is suitable for both cases? - Tchort
    • It does not work out for some reason. See how I'm doing now, including breaking text into columns. preg_match_all ("| <[^>] +> (. *) </ [^>] +> | U", $ arResult ["DETAIL_TEXT"], $ out, PREG_PATTERN_ORDER); $ counti = count ($ out [1]); $ polovina = round ($ counti / 2.0); <here ul> <? for ($ i = 0; $ i <$ polovina; $ i ++) {echo "<here li> <span style = \" margin-left: -5px; \ ">". $ out [1] [$ i] . "</ span> </ li>"; }?> </ here ul> <here ul> <? for ($ i = $ polovina; $ i <$ counti; $ i ++) {echo "<here li> <span style = \" margin-left: -5px; \ ">". $ out [1] [$ i ]. "</ span> </ li>"; }?> </ here ul> - Tchort
    • Almost succeeded, still there is some sort of sign. But the columns in any case turned out not the same. polar.ru/new/?section=mini_treaters&product=plr_2024 In this description there is still a <p> </ p> tag. Bitrix inserts a bunch of tags when using the visual editor, you have to foresee everything. - Tchort
    • And again)) Even checked: <a href=" sh4dow.jino.ru/test/"> script </ a > <a href=" sh4dow.jino.ru/test/test.txt"> html </ a > If no comment is written, delete the first one - limit 3. - Sh4dow
    • Sh4dow thank you so much :) You are a genius) After reading about you on your site, you are a genius in twins :) - Tchort

    If you need to clear a string from tags, use strip_tags . You can kill everything except ul and li and show.

    • Did. But the strip tag sometimes devours lines and removes a new line. And I need to save a column, so that later I can form one column - two. - Tchort