public static function convert($content, $allowed_tags = null, $line_width = null) { $_this = new Html2Text(); if (!empty($allowed_tags)) { $_this->setAllowedTags($allowed_tags); } if (!empty($line_width)) { $_this->setLineWidth($line_width); } $text = trim(stripslashes($content)); // Run our defined search-and-replace $text = preg_replace(array_keys(self::$correspondances), array_values(self::$correspondances), $text); // Strip any other HTML tags $text = strip_tags($text, join('', $_this->allowed_tags)); // Bring down number of empty lines to 2 max $text = preg_replace("/\n\\s+\n/", "\n\n", $text); $text = preg_replace("/[\n]{3,}/", "\n\n", $text); // Wrap the text to a readable format // for PHP versions >= 4.0.2. Default line_width is 75 // If line_width is 0 or less, don't wrap the text. if ($_this->line_width > 0) { $text = wordwrap($text, $_this->line_width); } return $text; }