本文整理汇总了PHP中wcf\util\StringUtil::countSubstring方法的典型用法代码示例。如果您正苦于以下问题:PHP StringUtil::countSubstring方法的具体用法?PHP StringUtil::countSubstring怎么用?PHP StringUtil::countSubstring使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wcf\util\StringUtil
的用法示例。
在下文中一共展示了StringUtil::countSubstring方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: compileIfTag
/**
* Compiles an {if} tag and returns the compiled PHP code.
*
* @param string $tagArgs
* @param boolean $elseif true, if this tag is an else tag
* @return string
*/
protected function compileIfTag($tagArgs, $elseif = false) {
$tagArgs = $this->replaceQuotes($tagArgs);
$tagArgs = str_replace(' ', '', $tagArgs);
// split tags
preg_match_all('~('.$this->conditionOperatorPattern.')~', $tagArgs, $matches);
$operators = $matches[1];
$values = preg_split('~(?:'.$this->conditionOperatorPattern.')~', $tagArgs);
$leftParentheses = 0;
$result = '';
for ($i = 0, $j = count($values); $i < $j; $i++) {
$operator = (isset($operators[$i]) ? $operators[$i] : null);
if ($operator !== '!' && $values[$i] == '') {
throw new SystemException($this->formatSyntaxError('syntax error in tag {'.($elseif ? 'elseif' : 'if').'}', $this->currentIdentifier, $this->currentLineNo));
}
$leftParenthesis = StringUtil::countSubstring($values[$i], '(');
$rightParenthesis = StringUtil::countSubstring($values[$i], ')');
if ($leftParenthesis > $rightParenthesis) {
$leftParentheses += $leftParenthesis - $rightParenthesis;
$value = StringUtil::substring($values[$i], $leftParenthesis - $rightParenthesis);
$result .= str_repeat('(', $leftParenthesis - $rightParenthesis);
if (str_replace('(', '', StringUtil::substring($values[$i], 0, $leftParenthesis - $rightParenthesis)) != '') {
throw new SystemException($this->formatSyntaxError('syntax error in tag {'.($elseif ? 'elseif' : 'if').'}', $this->currentIdentifier, $this->currentLineNo));
}
}
else if ($leftParenthesis < $rightParenthesis) {
$leftParentheses += $leftParenthesis - $rightParenthesis;
$value = StringUtil::substring($values[$i], 0, $leftParenthesis - $rightParenthesis);
if ($leftParentheses < 0 || str_replace(')', '', StringUtil::substring($values[$i], $leftParenthesis - $rightParenthesis)) != '') {
throw new SystemException($this->formatSyntaxError('syntax error in tag {'.($elseif ? 'elseif' : 'if').'}', $this->currentIdentifier, $this->currentLineNo));
}
}
else $value = $values[$i];
try {
$result .= $this->compileVariableTag($value, false);
}
catch (SystemException $e) {
throw new SystemException($this->formatSyntaxError('syntax error in tag {'.($elseif ? 'elseif' : 'if').'}', $this->currentIdentifier, $this->currentLineNo), 0, nl2br($e));
}
if ($leftParenthesis < $rightParenthesis) {
$result .= str_repeat(')', $rightParenthesis - $leftParenthesis);
}
if ($operator) $result .= ' '.$operator.' ';
}
return '<?php '.($elseif ? '} elseif' : 'if').' ('.$result.') { ?>';
}