Accepts both encoded and decoded html strings.
protected static replaceListItems ( string $html ) : string | ||
$html | string | An HTML-formatted string. |
return | string | Returns the html with all list items removed. |
/** * Format a string as plain text. * * @param string $Body The text to format. * @param string $Format The current format of the text. * @return string * @since 2.1 */ public static function plainText($Body, $Format = 'Html') { $Result = Gdn_Format::to($Body, $Format); $Result = Gdn_Format::replaceSpoilers($Result); if ($Format != 'Text') { // Remove returns and then replace html return tags with returns. $Result = str_replace(array("\n", "\r"), ' ', $Result); $Result = preg_replace('`<br\\s*/?>`', "\n", $Result); // Fix lists. $Result = Gdn_Format::replaceListItems($Result); $Allblocks = '(?:div|table|dl|pre|blockquote|address|p|h[1-6]|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)'; $Result = preg_replace('`</' . $Allblocks . '>`', "\n\n", $Result); // TODO: Fix hard returns within pre blocks. $Result = strip_tags($Result); } return trim(html_entity_decode($Result, ENT_QUOTES, 'UTF-8')); }