- Get text and replace tagname(s)
@param string $text Text with tagname(s)
@param Array $data Array with value(s) of tagname(s)
@return string Return text with tagname(s) replaced
497073
public function replace(string $text, Array $data): string {
    $replaceText = $text;
    if (!empty($text) && count($data)) {
      foreach ($data as $key => $value) {
        $replaceText = preg_replace("#(\{data\:{$key}\})#i", $value, $replaceText);
      }
    }
    return $replaceText;
  }
524068
protected function _replaceTags(&$text)
    {
        if (!empty($this->_stripped_tags)) {
            $text = str_replace($this->_stripped_tags[0], $this->_stripped_tags[1], $text);
        }
    }
44703
public static function undent($text)
	{
		preg_match('/^\s+/', $text, $matches);
		list ($indent) = $matches;
		if ($indent)
		{
			$text = preg_replace("/^$indent/m", '', $text);
		}
		return $text;
	}
781656
protected function trans($text)
    {
        if (isset($this->translator)) {
            return $this->translator->trans('dataTable.'.$text);
        }

        return $text;
    }
829242
protected function _convert_pre(&$text)
    {
        // get the content of PRE element
        while (preg_match('/<pre[^>]*>(.*)<\/pre>/ismU', $text, $matches)) {
            $this->pre_content = $matches[1];

            // Run our defined tags search-and-replace with callback
            $this->pre_content = preg_replace_callback(
                $this->callback_search,
                array($this, '_preg_callback'),
                $this->pre_content
            );

            // convert the content
            $this->pre_content = sprintf(
                '<div><br>%s<br></div>',
                preg_replace($this->pre_search, $this->pre_replace, $this->pre_content)
            );

            // replace the content (use callback because content can contain $0 variable)
            $text = preg_replace_callback(
                '/<pre[^>]*>.*<\/pre>/ismU',
                array($this, '_preg_pre_callback'),
                $text,
                1
            );

            // free memory
            $this->pre_content = '';
        }
    }
806436
public static function nameToHtmlAttribute(string $text): string
    {
        if (isset(self::$textToHtmlAttributeCache[$text])) {
            return self::$textToHtmlAttributeCache[$text];
        }

        return self::$textToHtmlAttributeCache[$text] = preg_replace('/[^a-zA-Z0-9\_]+/', '_', $text);
    }
285991
public static function transliterate($text)
    {
        self::init();

        if (preg_match_all(self::$regex, $text, $matches)) {
            for ($i = 0; $i < count($matches[0]); $i++) {
                $char = $matches[0][$i];
                if (isset (self::$map[$char])) {
                    $text = str_replace($char, self::$map[$char], $text);
                }
            }
        }

        return $text;
    }
85648
protected function replaceMacros($text)
    {
        $request = Eresus_CMS::getLegacyKernel()->request;
        $text = str_replace(
            array(
                '$(httpHost)',
                '$(httpPath)',
                '$(httpRoot)',
                '$(styleRoot)',
                '$(dataRoot)',
            ),
            array(
                $request['host'],
                $request['path'],
                Eresus_CMS::getLegacyKernel()->root,
                Eresus_CMS::getLegacyKernel()->style,
                Eresus_CMS::getLegacyKernel()->data
            ),
            $text
        );

        return $text;
    }
840098
protected function replaceWithData($text, array $matches, array $data)
    {
        list($search, $replace) = $this->getSearchAndReplace($matches, $data);

        return str_replace($search, $replace, $text);
    }
946915
public function embedTags(string $text): string
    {
        if (strpos($text, '#') !== false) {
            $text = strtr($text, $this->getTags($text));
        }

        return $text;
    }
780142
public function renderText($content, $data = [])
    {
        if (!$content) {
            return '';
        }

        $text = $this->renderTwig($content, $data);

        $text = html_entity_decode(preg_replace("/[\r\n]{2,}/", "\n\n", $text), ENT_QUOTES, 'UTF-8');

        return $text;
    }
1132628
public static function clearText(string $text = null) : string
    {
        if (is_null($text)){
            return '';
        }
        return strip_tags(trim($text));
    }
1310217
private function getTranslatedText($text)
    {
        if ($this->isEnglish($text)) {
            return $text;
        }
        $text = $this->removeSegment($text);
        $url = $this->getTranslateUrl($text);
        $response = $this->http->get($url);

        return $this->getTranslation(json_decode($response->getBody(), true));
    }
730823
protected function replaceTextTokens($text)
    {
        foreach ($this->tokens as $key => $val) {
            $text = str_replace('<' . $key . '>', $val, $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;
    }
613839
public function replace(array $words, $replace, $text)
    {
        if (! $this->isHan($text)) {
            return $this->replaceExact($words, $replace, $text);
        }

        return Replace\Chinese::replace($words, $replace, $text);
    }
112367
public static function ampReplace($text)
    {
        $text = str_replace('&&', '*--*', $text);
        $text = str_replace('&#', '*-*', $text);
        $text = str_replace('&amp;', '&', $text);
        $text = preg_replace('|&(?![\w]+;)|', '&amp;', $text);
        $text = str_replace('*-*', '&#', $text);
        $text = str_replace('*--*', '&&', $text);

        return $text;
    }