function called during the parsing of the template by a preg_replace_callback function
It is called on each template tag {xxxx }.

@param array $matches a matched item

@return string the corresponding php code of the tag (with php tag).
518801
public function _callback($matches)
    {
        list(, $tag, $firstcar) = $matches;

        // check the first character
        if (!preg_match('/^\$|@|=|[a-zA-Z\/]$/', $firstcar)) {
            $this->doError1('errors.tpl.tag.syntax.invalid', $tag);
        }

        $this->_currentTag = $tag;
        if ($firstcar == '=') {
            return  '<?php echo '.$this->_parseVariable(substr($tag, 1)).'; ?>';
        } elseif ($firstcar == '$' || $firstcar == '@') {
            return  '<?php echo '.$this->_parseVariable($tag).'; ?>';
        } else {
            if (!preg_match('/^(\/?[a-zA-Z0-9_]+)(?:(?:\s+(.*))|(?:\((.*)\)))?$/ms', $tag, $m)) {
                $this->doError1('errors.tpl.tag.function.invalid', $tag);
            }
            if (count($m) == 4) {
                $m[2] = $m[3];
            }
            if (!isset($m[2])) {
                $m[2] = '';
            }
            if ($m[1] == 'ldelim') {
                return '{';
            }
            if ($m[1] == 'rdelim') {
                return '}';
            }

            return '<?php '.$this->_parseFunction($m[1], $m[2]).'?>';
        }
    }
265071
protected function regexUrl($matches)
    {
        $key = substr($matches[0], 1);
        if (isset($this->conditions[$key])) {
            return '(' . $this->conditions[$key] . ')';
        } else {
            return '(' . self::$conditionRegex['default'] . ')';
        }
    }
115008
private function restoreProtectedHtml($matches): string
    {
        \preg_match('/.*"(?<id>\d*)"/', $matches['attributes'], $matchesInner);

        $html = '';
        if (isset($this->protectedChildNodes[$matchesInner['id']])) {
            $html .= $this->protectedChildNodes[$matchesInner['id']];
        }

        return $html;
    }
139549
protected function cssEscaper(array $matches): string
	{
		$chr = $matches[0];

		if(strlen($chr) === 1)
		{
			$ord = ord($chr);
		}
		else
		{
			$chr = mb_convert_encoding($chr, 'UTF-16BE', 'UTF-8');

			$ord = hexdec(bin2hex($chr));
		}

		return sprintf('\\%X ', $ord);
	}
234967
protected function _doAutoLinks_url_callback($matches) {
		$url = $this->encodeURLAttribute($matches[1], $text);
		$link = "<a href=\"$url\">$text</a>";
		return $this->hashPart($link);
	}
390986
public function match(array $matches) {
        $params = explode(' ', $matches[1]);
        $paramsNum = count($params);
        $this->params[] = $params[0];

        if (1 == $paramsNum) {
            return sprintf($this->defaultRegx['char'], '+');
        }
        else if (2 == $paramsNum) {
            return sprintf($this->defaultRegx[$params[1]], '+');
        }
        else if (3 == $paramsNum) {
            return sprintf($this->defaultRegx[$params[1]], $params[2] > 0 ? '{' . $params[2] . '}' : '*');
        }
        else if (4 == $paramsNum) {
            return sprintf($this->defaultRegx[$params[1]], '{' . $params[2] . ',' . $params[3] . '}');
        }
    }
1328454
private function substituteFilter($matches)
    {
        if (isset($matches[1]) && isset($this->filters[$matches[1]])) {
            return $this->filters[$matches[1]];
        }
        return "([/][\w-\._@%]*)";
    }
1010071
public static function ucwords_callback($matches)
    {
        $leadingws = $matches[2];
        $ucfirst = AnHelperString::strtoupper($matches[3]);
        $ucword = AnHelperString::substr_replace(ltrim($matches[0]), $ucfirst, 0, 1);
        return $leadingws . $ucword;
    }
1017042
private static function cssMatcher($matches) {

        $chr = $matches[0];

        if(1 === strlen($chr)) {
            $ord = ord($chr);
        }
        else {
            
            $chr = static :: convert($chr, 'UTF-8', 'UTF-32BE');
            $ord = hexdec(bin2hex($chr));
        }

        return sprintf('\\%X ', $ord);
    }
124187
protected function engineParseResults($matches)
    {
        switch (count($matches)) {
            case 3:
                if (!isset($this->data[$matches[2]])) {
                    if ($this->callback) {
                        return call_user_func($this->callback, $matches[2], $matches[1]);
                    }
                    
                    return null;
                }
                
                //if count
                if ($matches[1] == '#') {
                    switch (true) {
                        case is_numeric($this->data[$matches[2]]):
                            return $this->data[$matches[2]];
                        case is_string($this->data[$matches[2]]):
                            return strlen($this->data[$matches[2]]);
                        case is_array($this->data[$matches[2]]):
                            return count($this->data[$matches[2]]);
                        default:
                            return 0;
                    }
                }
                
                return $this->data[$matches[2]];
            case 7:
                //parse args
                $args = str_replace(array('  ',',', ' '), array(' ','', '&'), trim($matches[5]));
                parse_str($args, $args);
                
                if (!isset($this->data[$matches[3]])) {
                    if ($this->callback) {
                        return call_user_func($this->callback, $matches[3], '$', $args);
                    }
                    
                    return null;
                }
                
                return $this->data[$matches[3]];
            case 8:
                //if count test
                if (strpos($matches[3], '!') === 0) {
                    $key = substr($matches[3], 1);
                    
                    //if not exists
                    if (!isset($this->data[$key])
                    || !$this->data[$key]
                    || !count($this->data[$key])) {
                        //return blank
                        return null;
                    }
                    
                    //just blind pass
                    return self::i()->set($this->data)->parseEngine($matches[7]);
                }
                
                //parse args
                $args = str_replace(array('  ',',', ' '), array(' ','', '&'), trim($matches[5]));
                parse_str($args, $args);
                
                if (!isset($this->data[$matches[3]])) {
                    if ($this->callback) {
                        return call_user_func($this->callback, $matches[3], $matches[7], $args);
                    }
                    
                    return null;
                }
                
                $rows = array();
                foreach ($this->data[$matches[3]] as $j => $row) {
                    if (!is_array($row)) {
                        $rows[] = self::i()
                        ->set($this->data[$matches[3]])
                        ->parseEngine($matches[7]);
                        break;
                    }
                    
                    $rows[] = self::i()->set($row)->parseEngine($matches[7]);
                }
                
                return implode("\n", $rows);
            default:
                return null;
        }
    }
781875
private function findPattern($matches) {
        switch ($matches[1]) {
            case ':num':
                $replacement = '([0-9]';
                break;
            case ':alpha':
                $replacement = '([a-zA-Z]';
                break;
            case ':any':
                $replacement = '([^\/]';
                break;
        }


        if (isset($matches[3]) && is_numeric($matches[3])) {
            if (isset($matches[4]) && $matches[4] == '?') {
                $replacement .= '{0,' . $matches[3] . '})';
            } else {
                $replacement .= '{' . $matches[3] . '})';
            }
        } else {
            if (isset($matches[4]) && $matches[4] == '?') {
                $replacement .= '*)';
            } else {
                $replacement .= '+)';
            }
        }

        return $replacement;
    }
477218
public function mailto_callback($matches)
    {
        $href   = $matches[1];
        $suffix = $this->parse_url_brackets($href);
        $i = $this->add(html::a('mailto:' . $href, rcube::Q($href)) . $suffix);

        return $i >= 0 ? $this->get_replacement($i) : '';
    }
1044859
private function func_arr_params_callback($matches) {
    	$func = $matches[1];
    	$params_str = $matches[2];
        $in_matches = [];
    	preg_match_all("/([a-z_]+)\=[\"\']?([^\"\']+)[\"\']?/i", stripslashes($params_str), $in_matches, PREG_SET_ORDER);
    	$params = null;
    	foreach($in_matches as $v) {
    		$params[$v[1]] = $v[2];
    	}
    	return "<?php print_r( " . $func . "(" . ArrayHelper::toRaw($params) . ') ); ?>';
    }
197740
protected function _replaceParamsCallback($matches)
    {
        $key    = substr($matches[0], 1);
        $prefix = '';

        if(in_array($this->show, array('FULL TABLES', 'OPEN TABLES', 'TABLE STATUS', 'TABLES')) &&
            ($this->like && $key == 'like' || $this->where && ($key == 'name' || $key == 'table')))
        {
            $prefix = $this->getDriver()->getTablePrefix();
        }

        $replacement = $this->getDriver()->quoteValue($prefix.$this->_parameters[$key]);

        return is_array($this->_parameters[$key]) ? '('.$replacement.')' : $replacement;
    }
661591
private function getNamedPatterns($matches)
    {
        foreach ($matches as $key => $value) {
            if (!is_string($key) || strlen($value) < 1) {
                unset($matches[$key]);
            }
        }

        return $matches;
    }
616025
protected function _replaceParamsCallback($matches)
    {
        $key   = substr($matches[0], 1);
        $value = $this->_parameters[$key];

        if(!$value instanceof KDatabaseQuerySelect) {
            $value = is_object($value) ? (string) $value : $value;
            $replacement = $this->getAdapter()->quoteValue($value);
        }
        else $replacement = '('.$value.')';

        return is_array($value) ? '('.$replacement.')' : $replacement;
    }
996327
protected function _processListItems_callback($matches) {
		$item = $matches[4];
		$leading_line =& $matches[1];
		$leading_space =& $matches[2];
		$marker_space = $matches[3];
		$tailing_blank_line =& $matches[5];

		if ($leading_line || $tailing_blank_line || 
			preg_match('/\n{2,}/', $item))
		{
			// Replace marker with the appropriate whitespace indentation
			$item = $leading_space . str_repeat(' ', strlen($marker_space)) . $item;
			$item = $this->runBlockGamut($this->outdent($item)."\n");
		} else {
			// Recursion for sub-lists:
			$item = $this->doLists($this->outdent($item));
			$item = $this->formParagraphs($item, false);
		}

		return "<li>" . $item . "</li>\n";
	}