How can a text parser class be utilized in PHP to handle formatting issues when editing text from a WYSIWYG editor?

When editing text from a WYSIWYG editor, formatting issues can arise due to the presence of HTML tags and styling. To handle these issues, a text parser class can be utilized in PHP to strip out unwanted HTML tags, clean up the text, and ensure proper formatting.

class TextParser {
    public static function cleanText($text) {
        // Remove unwanted HTML tags
        $cleanText = strip_tags($text);
        
        // Clean up text
        $cleanText = htmlspecialchars($cleanText);
        
        // Ensure proper formatting
        $cleanText = nl2br($cleanText);
        
        return $cleanText;
    }
}

// Example of how to use the TextParser class
$textFromEditor = "<p>This is some <strong>text</strong> from a WYSIWYG editor.</p>";
$cleanedText = TextParser::cleanText($textFromEditor);

echo $cleanedText;