A common problem encountered when doing collection is content layout. I spent some time writing a function that replaces HTML tags and styles with regular expressions. I will share it with you.
"/
',
"//i" => '
", ',// Replace half-width and full-width spaces and line breaks, and use to eliminate encoding problems that occur when writing to the database ')>6)//Some content may be missing the tag at the beginning
"/
"/ /i " => ' ',//Replace spaces with
"/
);
$config = array(
//'indent' => TRUE, // Whether to indent
'output-html' => TRUE,//Whether it is output xhtml
'show-body-only'=>TRUE,//Whether only the body is obtained
'wrap' => 0
);
$content = tidy_repair_string($content, $config, 'utf8');//First use the tidy class library that comes with php to repair the html tags, otherwise various problems will easily occur when replacing them. A weird situation
$content = trim($content);
foreach ( $replaces as $k => $v ) {
$content = preg_replace ( $k, $v, $content ) ;
}
if(strpos($content,'
$content = '< p> '.$content;
$content = tidy_repair_string($content, $config, 'utf8');//Repair it again to remove the html empty tags
$content = trim($content );
return $content;
}