Как сохранить абзацы и переносы строк?
Есть такая строка:
<div class="article-text"><p>Another Ukrainian on March 29, 2021, received a second shot of the CoviShield vaccine to complete the vaccination course as part of the ongoing nationwide COVID-19 campaign.</p><p>Some 14,433 people got vaccinated against COVID-19 in Ukraine on Monday, March 29, Ukrainian Health Minister Maksym Stepanov wrote on <a href="https://www.facebook.com/maksym.stepanov.official/posts/900590873817242" target="_blank">Facebook</a> on March 30.</p><p>In total, 212,898 people have received their first shot of the vaccine since the launch of the nationwide COVID-19 vaccination campaign in Ukraine, while two people have already received two shots of the CoviShield vaccine to complete the vaccination course.</p><p>In the past day, most vaccinations were recorded in the city of Kyiv (1,740).</p><p>The shots were administered by 152 mobile vaccination teams.</p><p>As of March 29, as many as 371,406 Ukrainians have signed up for the COVID-19 vaccination waiting list.</p><h2>Vaccination in Ukraine</h2><ul><li>On February 24, 2021, Ukraine launched a nationwide COVID-19 vaccination campaign. Doctors who treat COVID-19 patients, ambulance teams, laboratory personal involved in COVID-19 testing, residents and staff of nursing homes, as well as military personnel in the Joint Forces Operation (JFO) zone in Donbas are to be vaccinated at the first stage.</li><li>Today, the <a data-src="https://images.unian.net/photos/2021_03/thumb_files/220_140_1616996900-5461.jpg" href="https://www.unian.info/society/covid-19-nearly-1-600-ukrainians-vaccinated-in-past-day-health-minister-11369068.html" target="_blank">vaccination campaign</a> is underway in Ukraine with CoviShield (AstraZeneca), a recombinant vector vaccine produced under license at Serum Institute of India.</li></ul></div>
Мне нужно из нее убрать все теги и оставить только текст.
Если делать так:
$string = strip_tags($string);
Тогда теги убирает, но тогда получается что весь текст идет одним абзацем.
Как можно убрать все теги но при этом сохранить абзацы?
P.S. strip_tags($string, '<p><br>') не подойдет, так как на выходе тегов быть не должно вообще.
Буду благодарен за помощь!
Ответы (1 шт):
Автор решения: Jigius
→ Ссылка
Как один из вариантов - перед требуемыми тегами расставить переводы строк в тексте, для формирования абзацев, и вырезать теги:
<?php
$txt = <<< EOT
<div class="article-text"><p>Another Ukrainian o .....
EOT;
echo strip_tags(preg_replace("/(<(?:p|h\d|li)>)/", "\r\n\r\n\\1", $txt));
?>