136 preg_match_all(
"/#([0-9a-zA-Z_.]+?)#/", $str, $matchesFindPlaceHolders);
137 $matchesFindPlaceHoldersCount = count($matchesFindPlaceHolders[1]);
138 for($i=0; $i<$matchesFindPlaceHoldersCount; $i++)
139 if(mb_strlen($matchesFindPlaceHolders[1][$i]) > 200)
140 unset($matchesFindPlaceHolders[1][$i]);
142 if(empty($matchesFindPlaceHolders[1]))
144 $ar = $matchesFindPlaceHolders[1];
147 $arReplaceTagsOne = array();
149 if(!$fromTemplateToPhp)
153 $replaceTo =
'#'.$k.
'#';
155 $replaceFrom =
'$arParams["'.$k.
'"]';
156 $replaceFromQuote =
'$arParams[\''.$k.
'\']
';
157 $replaceFromPhp = '<?=
'.$replaceFrom.';?>
';
159 $arReplaceTagsOne[$replaceFromPhp] = $replaceTo;
160 $arReplaceTagsOne[$replaceFrom] = $replaceTo;
161 $arReplaceTagsOne[$replaceFromQuote] = $replaceTo;
166 $replaceTemplateString = '';
167 foreach($ar as $k) $replaceTemplateString .= '|#
'.$k.'#
';
169 $arReplaceTags = array();
170 $bOpenPhpTag = false;
171 preg_match_all('/(<\?|\?>
'.$replaceTemplateString.')/
', $str, $matchesTag, PREG_OFFSET_CAPTURE);
172 foreach($matchesTag[0] as $tag)
174 $placeHolder = $tag[0];
175 $placeHolderPosition = $tag[1];
176 $ch1 = mb_substr($placeHolder, 0, 1);
177 $ch2 = mb_substr($placeHolder, 0, 2);
182 $bOpenPhpTag = false;
185 $placeHolderClear = mb_substr($placeHolder, 1, mb_strlen($placeHolder) - 2);
187 $bOpenQuote = (mb_substr($str, $placeHolderPosition - 2, 2) == '"{');
188 $bCloseQuote = (mb_substr($str, $placeHolderPosition + mb_strlen($placeHolder), 2) == '}"');
189 if($bOpenPhpTag && $bOpenQuote && $bCloseQuote)
190 $replaceTo = '$arParams[\
''.$placeHolderClear.
'\']
';
192 $replaceTo = '$arParams[
"'.$placeHolderClear.'"]
';
194 if(!$bOpenPhpTag) $replaceTo = '<?=
' . $replaceTo . ';?>
';
195 $arReplaceTags[$tag[0]][] = $replaceTo;
199 foreach($arReplaceTags as $k => $v)
203 foreach($v as $replaceTo)
205 $resultReplace = preg_replace('/
'.$k.'/
', $replaceTo, $strResult, 1);
206 if($resultReplace !== null)
207 $strResult = $resultReplace;
212 $arReplaceTagsOne[$k] = $v[0];
217 if(!empty($arReplaceTagsOne))
218 $strResult = str_replace(array_keys($arReplaceTagsOne), array_values($arReplaceTagsOne), $strResult);
220 // php parser delete newline folowing the closing tag in string passed to eval
221 $strResult = str_replace(array("?>\n", "?>\r\n"), array("?>\n\n", "?>\r\n\r\n"), $strResult);