method html2text documentation in bbn\Str

Converts HTML to text replacing paragraphs and brs with new lines.

Example

var_dump(\bbn\Str::html2text("

foo bar


baz")); // (string) 'foo bar baz' var_dump(\bbn\Str::html2text('

foo bar


', false)); // (string) 'foo bar'
function(string $st, bool $nl = true) { $st = trim(self::sanitizeHtml($st)); if (empty($st)) { return ''; } $filter = $nl ? ['p', 'br'] : []; $tmp = strip_tags($st, $filter); if (empty($tmp)) { $config = array( 'clean' => 'yes', 'output-html' => 'yes', ); $tidy = tidy_parse_string($st, $config, 'utf8'); $tidy->cleanRepair(); $st = strip_tags((string)$tidy, $filter); } else { $st = $tmp; } if (empty($st)) { return ''; } if (!$nl) { return $st; } $st = preg_replace("/]*?>/i", "", $st); $st = str_ireplace("

", PHP_EOL.PHP_EOL, $st); $p = '/]*>/i'; $r = PHP_EOL; return trim(html_entity_decode(preg_replace($p, $r, $st))); }

Converts HTML to text replacing paragraphs and brs with new lines. BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way

This website uses cookies to ensure you get the best experience on our website.