Adds an emoticon to the parser.
@param string $key
@param string $url
@param bool   $replace If to replace another emoticon with the same key
@return bool
963968
public function add_emoticon($key, $url, $replace=true)
	{
		if(isset($this->emoticons[$key]) && !$replace)
			return false;

		$this->emoticons[$key] = $url;
		return true;
	}
384273
protected function header($string, $replace = true, $http_response_code = null)
    {
        header($string, $replace, $http_response_code);
    }
489947
protected function replace_emoticons($text) {
        global $CFG, $OUTPUT, $PAGE;

        $lang = current_language();
        $theme = $PAGE->theme->name;

        if (!isset(self::$emoticontexts[$lang][$theme]) or !isset(self::$emoticonimgs[$lang][$theme])) {
            // prepare internal caches
            $manager = get_emoticon_manager();
            $emoticons = $manager->get_emoticons();
            self::$emoticontexts[$lang][$theme] = array();
            self::$emoticonimgs[$lang][$theme] = array();
            foreach ($emoticons as $emoticon) {
                self::$emoticontexts[$lang][$theme][] = $emoticon->text;
                self::$emoticonimgs[$lang][$theme][] = $OUTPUT->render($manager->prepare_renderable_emoticon($emoticon));
            }
            unset($emoticons);
        }

        if (empty(self::$emoticontexts[$lang][$theme])) { // No emoticons defined, nothing to process here.
            return $text;
        }

        // Detect all zones that we should not handle (including the nested tags).
        $processing = preg_split('/(<\/?(?:span|script)[^>]*>)/is', $text, 0, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);

        // Initialize the results.
        $resulthtml = "";
        $exclude = 0;

        // Define the patterns that mark the start of the forbidden zones.
        $excludepattern = array('/^<script/is', '/^<span[^>]+class="nolink[^"]*"/is');

        // Loop through the fragments.
        foreach ($processing as $fragment) {
            // If we are not ignoring, we MUST test if we should.
            if ($exclude == 0) {
                foreach ($excludepattern as $exp) {
                    if (preg_match($exp, $fragment)) {
                        $exclude = $exclude + 1;
                        break;
                    }
                }
            }
            if ($exclude > 0) {
                // If we are ignoring the fragment, then we must check if we may have reached the end of the zone.
                if (strpos($fragment, '</span') !== false || strpos($fragment, '</script') !== false) {
                    $exclude -= 1;
                    // This is needed because of a double increment at the first element.
                    if ($exclude == 1) {
                        $exclude -= 1;
                    }
                } else if (strpos($fragment, '<span') !== false || strpos($fragment, '<script') !== false) {
                    // If we find a nested tag we increase the exclusion level.
                    $exclude = $exclude + 1;
                }
            } else if (strpos($fragment, '<span') === false ||
                       strpos($fragment, '</span') === false) {
                // This is the meat of the code - this is run every time.
                // This code only runs for fragments that are not ignored (including the tags themselves).
                $fragment = str_replace(self::$emoticontexts[$lang][$theme], self::$emoticonimgs[$lang][$theme], $fragment);
            }
            $resulthtml .= $fragment;
        }

        return $resulthtml;
    }
1273038
static function substituteUrlArgTokens($route)
	{	
		$orig = $route;
		$tokens = [];
		// look for things like this {id} and like this {id?},
		// optionally preceeded by a forward slash
		while(preg_match('#/?({([\w\_]+)\??})#i', $route, $matches)) {
			// get the argument name:
			$arg = $matches[2];
			$tokens[] = $arg;
			// capture what we're going to replace 
			$subject = $matches[0];
			// make the replacement, e.g., (?P<id>[a-z\-\_]+)
			$replacement = '(?P<'.$arg.'>[^/]+)';
			// if the original arg was preceeded by a forward slash, we need to put it back
			if (stripos($subject, '/') === 0) {
				$replacement = '/' . $replacement;
			}
			// if the original arg has a ?, then we need to wrap our new token in the same
			if (stripos($subject, '?') !== false) {
				$replacement = '('.$replacement.')?';
			}
			// make the substitution
			$route = str_replace($subject, $replacement, $route);
		}
		
		return [ $route, $tokens ];
	}
2556
public function matches($key, $regex, &$matches = [])
    {
        if (!$this->has($key, self::HAS_ISSET)) {
            return false;
        }

        return (bool) preg_match($regex, $this->get($key), $matches);
    }
551015
def replace(cls, replacement_string):
        """"""
        e = cls()

        def _replace_emoji(match):
            val = match.group(1)
            if val in e:
                return e._image_string(match.group(1))
            else:
                return match.group(0)

        return e._pattern.sub(_replace_emoji, replacement_string)
214551
function emojify($str) {
		$map=[
			':('=>'\u2639', // frown
			':)'=>'\u263a', // smile
			'<3'=>'\u2665', // heart
			':D'=>'\u1f603', // grin
			'XD'=>'\u1f606', // laugh
			';)'=>'\u1f609', // wink
			':P'=>'\u1f60b', // tongue
			':,'=>'\u1f60f', // think
			':/'=>'\u1f623', // skeptic
			'8O'=>'\u1f632', // oops
		]+Base::instance()->EMOJI;
		return $this->translate(str_replace(array_keys($map),
			array_values($map),$str));
	}
277383
protected function wordToEmojiReplace($line, $replace, $delimiter)
    {
        foreach ($replace as $key => $value) {
            $line = str_replace($delimiter.$key.$delimiter, $value, $line);
        }

        return $line;
    }
491821
public function get($key, array $replace = [], $locale = null, $fallback = true)
    {
        // If we have a CMS-prefixed version, use it.
        if ( ! $this->isCmsPrefixed($key)) {
            $prefixedKey = $this->applyCmsPrefix($key);

            if (parent::has($prefixedKey, $locale, $fallback)) {
                $key = $prefixedKey;
            }
        }

        return parent::get($key, $replace, $locale, $fallback);
    }
28942
public function replace(string $find, string $replace): Stringable
    {
        return new static(str_replace($find, $replace, $this->string));
    }
742683
protected function _parseLink($url, $regex) {
		$context = stream_context_create(
			['http' => ['header' => 'Connection: close']]);
		$content = file_get_contents($url, false, $context);
		if (!$content) {
			return false;
		}

		$source = preg_replace('/[^(\x20-\x7F)]*/', '', $content);

		if (preg_match('~' . $regex . '~imu', $source, $match)) {
			$this->_match = $match;
			return true;
		}

		return false;
	}
510769
static function addUrlParam($url, $key, $val)
    {
        // Separate the anchor element from the URL if it exists.
        $urlParts = parse_url($url);
        if(isset($urlParts['fragment'])){
            $url = str_replace('#'.$urlParts['fragment'], '', $url);
        }

        $separator = (parse_url($url, PHP_URL_QUERY) == NULL) ? '?' : '&';
        $url .= $separator.$key.'='.$val;

        // Add the anchor back to the URL.
        if(isset($urlParts['fragment'])){
            $url .= '#'.$urlParts['fragment'];
        }

        return $url;
    }
987926
protected function sanitize($value, $key = null, $regex = '/\s+/', $replace = ' ')
    {
        $value = $this->checkValue($value, $key);

        return $value == null ? null : utf8_decode(trim(preg_replace($regex, $replace, $value)));
    }
537451
public function replace(string $regex, string $replacement) : Text
    {
        return $this->pipe(
            function (string $value) use ($regex, $replacement) {
                return preg_replace($regex, $replacement, $value);
            }
        );
    }
1211741
public function header($key, $value, $replace = true)
	{
		if (empty($this->headers[$key]))
		{
			$this->headers[$key] = array();
		}
		if ($replace)
		{
			$this->headers[$key] = array($value);
		}
		else
		{
			$this->headers[$key][] = $value;
		}

		return $this;
	}
1160399
public function replaceEmojiWithImages($string, $imageHtmlTemplate = null)
    {
        // NB: Named emoji should be replaced first as the string will then contain them in the image alt tags

        // Replace named emoji, e.g. ":smile:"
        $string = preg_replace_callback($this->getIndex()->getEmojiNameRegex(), function ($matches) use ($imageHtmlTemplate) {
            return $this->getEmojiImageByName($matches[1], $imageHtmlTemplate);
        }, $string);

        // Replace unicode emoji
        $string = preg_replace_callback($this->getIndex()->getEmojiUnicodeRegex(), function ($matches) use ($imageHtmlTemplate) {
            return $this->getEmojiImageByUnicode($matches[0], $imageHtmlTemplate);
        }, $string);

        return $string;
    }
997651
public function add_emoticons(Array $emoticons, $replace=true)
	{
		foreach($emoticons as $key => $url)
			$this->add_emoticon($key, $url, $replace);
	}