Made the regex to strip paragraphs and divs ungreedy

This commit is contained in:
pezcurrel 2024-08-25 19:05:58 +02:00
parent a143bad33d
commit 3aca654d83

View file

@ -965,7 +965,7 @@ function nullyp($str) {
function strip($str,$uri) {
if (nullemp($str)) return(null);
//echo '<pre>'.$str.'</pre>';
echo '<pre>'.htmlentities($str).'</pre>';
$str=preg_replace(['#^\s*#m','#[\r\n]#'],['',' '],$str);// strip all spaces from empty lines, then all carriage return and new line chars
$str=preg_replace('#<br\s+/>#i','<br>',$str);// convert all "<br />" to "<br>"
$str=preg_replace('#<a\s+[^>]*></a>#i','',$str);
@ -974,7 +974,7 @@ function strip($str,$uri) {
//$str=preg_replace(['#</p><br>#i','#</li><br>#i','#</ul><br>#i','#<ul><br>#i'],['</p>','</li>','</ul>','<ul>'],$str);
$str=preg_replace(['#<b>#i','#</b>#i','#<i>#i','#</i>#i'],['<strong>','</strong>','<em>','</em>'],$str);
$str=preg_replace('#<p[^>]*>\s*</p>#is','',$str);
$str=preg_replace(['#<p[^>]*>(.*)</p>#i','#<div[^>]>(.*)</div>#i'],['<br><br>$1<br><br>','<br><br>$1<br><br>'],$str);
$str=preg_replace(['#<p[^>]*>(.*)</p>#Ui','#<div[^>]>(.*)</div>#Ui'],['<br><br>$1<br><br>','<br><br>$1<br><br>'],$str);
$str=strip_tags($str,'<a><br><ol><ul><li><strong><em><small><img><h1><h2><h3><h4><h5><h6>');
$str=preg_replace('#<([^>]*)\s(style|class)="[^"]*"([^>]*)>#i','<$1$3>',$str);
$str=preg_replace(['#<h[1-6][^>]*>#i','#</h[1-6]>#i'],['<br><br><span class="exh">','</span><br><br>'],$str);