From ec9baef96840efd28fd34747f2045a690a701c3f Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 21 Apr 2018 04:10:25 -0400 Subject: [PATCH] Add new Content\BBCode::toPlaintext() --- src/Content/Text/BBCode.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index e22306fc8d..96c8eceb70 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -342,6 +342,23 @@ class BBCode extends BaseObject return $post; } + /** + * @brief Converts a BBCode text into plaintext + * + * @param bool $keep_urls Whether to keep URLs in the resulting plaintext + * + * @return string + */ + public static function toPlaintext($text, $keep_urls = true) + { + $naked_text = preg_replace('/\[(.+?)\]/','', $text); + if (!$keep_urls) { + $naked_text = preg_replace('#https?\://[^\s<]+[^\s\.\)]#i', '', $naked_text); + } + + return $naked_text; + } + public static function scaleExternalImages($srctext, $include_link = true, $scale_replace = false) { // Suppress "view full size"