Replaces &amp; with & for XHTML compliance
@param   string $text Text to process
@return  string  Processed string.
519294
public static function ampReplace($text)
    {
        $text = str_replace([
            '&&',
            '&#',
            '&#',
            '&amp;',
            '*-*',
            '*--*',
        ], [
            '*--*',
            '*-*',
            '*-*',
            '&',
            '&#',
            '&&',
        ], $text);

        $text = (string)preg_replace('/|&(?![\w]+;)|/', '&amp;', $text);

        return $text;
    }
297901
public function replace( string $text, ... $replace ): string
	{
		$then = $this->package_context;
		return $this->format(
			$this->line($text),
			$then,
			count($replace) === 1 && is_array($replace[0]) ? $replace[0] : $replace
		);
	}
654079
public static function ctype_lower($text)
    {
        $text = self::convert_int_to_char_for_ctype($text);

        return \is_string($text) && '' !== $text && !preg_match('/[^a-z]/', $text);
    }
1067513
public function msgText($text)
    {
        $this->isHTML(false);
        $text = self::html2text($text, true);
        $text = self::normalizeBreaks($text);
        $this->Body = $text;
    }
1094778
private function sanitizeText(string $text): string
    {
        $text = preg_replace($this->isMultiLine() ? '/[\x00-\x09\x0B\x0C\x0E-\x1F\x7F]/u' : '/[\x00-\x1F\x7F]/u', '', $text);

        return $text;
    }
1070443
protected function encodeText($text)
    {
        $encoded_text = '';

        for ($i = 0; $i < strlen($text); $i++) {
            $char = $text{$i};
            $r    = rand(0, 100);

            # roughly 10% raw, 45% hex, 45% dec
            # '@' *must* be encoded. I insist.
            if ($r > 90 && $char != '@') {
                $encoded_text .= $char;
            } else if ($r < 45) {
                $encoded_text .= '&#x'.dechex(ord($char)).';';
            } else {
                $encoded_text .= '&#'.ord($char).';';
            }
        }

        return $encoded_text;
    }
600238
public static function escape($text)
    {
        $tagregexp = implode('|', array_map('preg_quote', static::_list()));
        preg_match_all('/(.?){(' . $tagregexp . ')\b(.*?)(?:(\/))?}(?:(.+?){\/\2})?(.?)/s', $text, $matches);

        foreach ($matches[0] as $ht) {
            $replace = str_replace_once('{', '{{', $ht);
            $replace = str_replace_last('}', '}}', $replace);
            $text = str_replace($ht, $replace, $text);
        }

        return $text;
    }
1242529
public function text($text)
    {
        foreach ($this->_data as $macros => $value) {
            $macros = '{' . $macros . '}';
            $text   = preg_replace('#' . $macros . '#ius', $value, $text);
        }

        return $text;
    }
413618
protected function _stripTags(&$text)
    {
        $regexp = '@<(\w+)\b.*?>.*?</\1>@si';
        $matches = array();
        $replacements = array();

        if (preg_match_all($regexp, $text, $matches)) {
            $matches = $matches[0];

            foreach ($matches as $i => $tag) {
                $replacements[] = $i.'-'.md5($tag);
            }

            $text = str_replace($matches, $replacements, $text);
        }

        $this->_stripped_tags = array($replacements, $matches);
    }
5861
public function clean($text)
    {
        $len = $this->utf8 ? mb_strlen($text) : strlen($text);

        if ($len <= $this->max) {
            return $text;
        }

        return $this->utf8 ? mb_substr($text, 0, $this->max) : substr($text, 0, $this->max);
    }
946915
public function embedTags(string $text): string
    {
        if (strpos($text, '#') !== false) {
            $text = strtr($text, $this->getTags($text));
        }

        return $text;
    }
689199
public function convertToUrl($text)
    {
        $text =$this->convertToCode($text);
        $text = str_replace("_", "-", $text);
        return $text;
    }
893828
protected function _processText($text)
    {
        $matches = array();

        preg_match_all("/(href|src)=\"(?!http|ftp|https|mailto|data)([^\"]*)\"/", $text, $matches, PREG_SET_ORDER);

        foreach ($matches as $match)
        {
            $route = $this->getObject('lib:dispatcher.router.route', array(
                'url'    => $match[2],
                'escape' => false
            ));

            //Add the host and the schema
            $route->scheme = $this->getUrl()->scheme;
            $route->host   = $this->getUrl()->host;

            $text = str_replace($match[0], $match[1].'="'.$route.'"', $text);
        }

        return $text;
    }
488143
public function filter(&$text)
    {
        $scripts = $this->_parseTags($text);

        if($this->getTemplate()->decorator() == 'koowa') {
            $text = str_replace('<ktml:script>', $scripts, $text);
        } else  {
            $text = $scripts.$text;
        }
    }
275231
private function stripContent($text)
    {
        if ($this->convertBrToNewlines()) {
            $text = $this->brToNewline($text);
        }
        if ($this->stripTags()) {
            $text = strip_tags($text);
        }
        return $text;
    }
124890
private function processText($text)
    {
        // verify if content is a string otherwhise just return the original provided content
        if (!is_string($text) || empty($text)) {
            return $text;
        }
        // find all tags based on the REGEX expression
        preg_match_all(static::REGEX, $text, $results, PREG_SET_ORDER);
        // foreach all the results matches the regex
        foreach ($results as $row) {
            // When value is empty (can be caused by using `link[]` we have to skip this item.
            if (empty($row['value'])) {
                continue;
            }
            // extract tag name from regex
            $tag = $row['function'];
            if ($this->hasTag($tag)) {
                $replace = $this->parseTag($tag, $row);
                $text = preg_replace('/'.preg_quote($row[0], '/').'/mi', $replace, $text, 1);
            }
        }
        
        return $text;
    }
730823
protected function replaceTextTokens($text)
    {
        foreach ($this->tokens as $key => $val) {
            $text = str_replace('<' . $key . '>', $val, $text);
        }

        return $text;
    }