Format text according to HTML Purifier.

@param string $text that should be formatted.

@return string as the formatted html-text.
345541
public function purify($text)
    {
        $config   = \HTMLPurifier_Config::createDefault();
        $config->set("Cache.DefinitionImpl", null);
        //$config->set('Cache.SerializerPath', '/home/user/absolute/path');

        $purifier = new \HTMLPurifier($config);
    
        return $purifier->purify($text);
    }
105078
public function normalizeText( $text )
    {
        if ( $this->searchHandler instanceof LegacyHandler )
        {
            $searchEngine = new eZSearchEngine();
            return $searchEngine->normalizeText( $text );
        }

        return $text;
    }
717085
public function filter(&$text)
    {
        $matches = array();
        if(preg_match_all('#<ktml:markdown>(.*)<\/ktml:markdown>#siU', $text, $matches))
        {
            $engine = $this->getObject('template.engine.factory')
                ->createEngine('markdown', array('template' => $this->getTemplate()));

            foreach($matches[1] as $key => $match)
            {
                $html = $engine->loadString($matches[1][$key])->render();
                $text = str_replace($matches[0][$key], $html, $text);
            }
        }
    }
676297
protected function cleanText($text)
    {
        $strippedText = strip_tags($text);
        $strippedText = htmlentities($strippedText, ENT_QUOTES, $this->getCharset(), FALSE);
        return html_entity_decode($strippedText, ENT_QUOTES, $this->getCharset());
    }
1276882
public static function cleanText(&$text)
    {
        $text = preg_replace("'<script[^>]*>.*?</script>'si", '', $text);
        $text = preg_replace('/<a\s+.*?href="([^"]+)"[^>]*>([^<]+)<\/a>/is', '\2 (\1)', $text);
        $text = preg_replace('/<!--.+?-->/', '', $text);
        $text = preg_replace('/{.+?}/', '', $text);
        $text = preg_replace('/&nbsp;/', ' ', $text);
        $text = preg_replace('/&amp;/', ' ', $text);
        $text = preg_replace('/&quot;/', ' ', $text);
        $text = strip_tags($text);
        $text = htmlspecialchars($text, ENT_COMPAT, 'UTF-8');

        return $text;
    }
1052897
public static function sanitizeText($text)
    {
        if (!$text) {
            return null;
        }

        $allowedTagNames = [ "b", "strong", "i", "em", "br" ];

        $marker = "\&8slkc7\\";

        // Create a one-to-one conversion array for easy replacing
        $allowedTagConversion = [];
        foreach($allowedTagNames as $allowedTagName) {
            $allowedTagConversion["<{$allowedTagName}>"] = "{$marker}{$allowedTagName}{$marker}";
            $allowedTagConversion["<{$allowedTagName}/>"] = "{$marker}{$allowedTagName}/{$marker}";
            $allowedTagConversion["<{$allowedTagName} />"] = "{$marker}{$allowedTagName} /{$marker}";
            $allowedTagConversion["</{$allowedTagName}>"] = "{$marker}/{$allowedTagName}{$marker}";
        }

        // Convert to BB-like tags before sanitizing and then revert
        $text = str_ireplace(array_keys($allowedTagConversion), array_values($allowedTagConversion), $text);

        $text = self::sanitizeString($text);

        if (!$text) {
            return null;
        }

        return str_ireplace(array_values($allowedTagConversion), array_keys($allowedTagConversion), $text);
    }
689199
public function convertToUrl($text)
    {
        $text =$this->convertToCode($text);
        $text = str_replace("_", "-", $text);
        return $text;
    }
24676
protected function format_text($text) {
        // Since we allow output for highlighting, we need to encode html entities.
        // This ensures plaintext html chars don't become valid html.
        $out = s($text);

        $startcount = 0;
        $endcount = 0;

        // Remove end/start pairs that span a few common seperation characters. Allows us to highlight phrases instead of words.
        $regex = '|'.engine::HIGHLIGHT_END.'([ .,-]{0,3})'.engine::HIGHLIGHT_START.'|';
        $out = preg_replace($regex, '$1', $out);

        // Now replace our start and end highlight markers.
        $out = str_replace(engine::HIGHLIGHT_START, '<span class="highlight">', $out, $startcount);
        $out = str_replace(engine::HIGHLIGHT_END, '</span>', $out, $endcount);

        // This makes sure any highlight tags are balanced, incase truncation or the highlight text contained our markers.
        while ($startcount > $endcount) {
            $out .= '</span>';
            $endcount++;
        }
        while ($startcount < $endcount) {
            $out = '<span class="highlight">' . $out;
            $endcount++;
        }

        return parent::format_text($out);
    }
623520
public function clean($text)
    {
        if (!$this->handler) {
            return $text;
        }

        $handler = $this->handler;

        return $handler($text);
    }
543959
protected function splitText($text)
    {
        $punctuations = preg_quote(implode('', $this->punctuations), '/');

        $text = preg_replace('/([^\p{Han}\s'.$punctuations.']+)/u', "\t\t\t$1\t\t", $text);

        $array = [];

        foreach (preg_split('/\t\t/u', $text, -1, PREG_SPLIT_NO_EMPTY) as $item) {
            $array[] = ("\t" === $item[0])
                ? substr($item, 1)
                : preg_split('//u', $item, -1, PREG_SPLIT_NO_EMPTY);
        }

        return $this->flatten($array);
    }
697205
public function format($text, $formatOptions = array())
    {
        if (!is_array($formatOptions)) {
            $formatOptions = array('fgcolor' => $formatOptions);
        }
        $formatOptions = array_merge($this->defaultFormatOptions, $formatOptions);
        $formater = new TextFormater($formatOptions);
        return $formater->format($text);
    }
275231
private function stripContent($text)
    {
        if ($this->convertBrToNewlines()) {
            $text = $this->brToNewline($text);
        }
        if ($this->stripTags()) {
            $text = strip_tags($text);
        }
        return $text;
    }
581700
protected function formatText($text) {
        $syntax = [
            '/\<strong\>/m' => "\033[1m",
            '/\<u\>/m' => "\033[4m",
            '/\<dim\>/m' => "\033[2m",
            '/\<fatal\>/m' => "\033[" . $this->colors[self::FATAL] . "m",
            '/\<error\>/m' => "\033[" . $this->colors[self::ERROR] . "m",
            '/\<warning\>/m' => "\033[" . $this->colors[self::WARNING] . "m",
            '/\<notice\>/m' => "\033[" . $this->colors[self::NOTICE] . "m",
            '/\<debug\>/m' => "\033[" . $this->colors[self::DEBUG] . "m",
            '/\<red\>/m' => "\033[31m",
            '/\<yellow\>/m' => "\033[33m",
            '/\<green\>/m' => "\033[32m",
            '/\<grey\>/m' => "\033[37m",
            '/\<\/([a-z]+)\>/m' => "\033[0m",
        ];

        $replacements = '$1';

        if ($this->colorize) {
            $replacements = $syntax;
        }

        $result = preg_replace(
            array_keys($syntax),
            $replacements,
            $text
        );

        if (!is_string($result)) {
            throw new RuntimeException('Unable to format text', ExitApp::RUNTIME_ERROR);
        }

        return $result;
    }
158377
protected function removeHtml($text)
    {
        if (!trim($text)) {
            return '';
        }

        // Remove Styles and Scripts
        $crawler = new Crawler($text);
        $crawler->filter('style, script')->each(function (Crawler $crawler) {
            foreach ($crawler as $node) {
                $node->parentNode->removeChild($node);
            }
        });
        $text = $crawler->html();

        // Remove HTML markup
        $result = strip_tags($text);

        // Decode HTML entities
        $result = trim(html_entity_decode($result, ENT_QUOTES));

        return $result;
    }
332318
public function script($text)
    {
        return htmlspecialchars(
               $this->getService('anahita:filter.string')
               ->sanitize(AnHelperString::str_ireplace(array("\r\n", "\n"), '', $text)), ENT_QUOTES);
    }
826012
public function format($text = '', string $style = 'none')
    {
        return $this->getStartMark($style) . $text . $this->getClearMark();
    }
1066206
static function removeHtmlTag($text)
    {

        $text = htmlspecialchars_decode($text);
        $text = html_entity_decode($text);
        $text = strip_tags($text);
        return $text;

    }