Home >Backend Development >PHP Tutorial >php 模板替换解决方法

php 模板替换解决方法

WBOY
WBOYOriginal
2016-06-13 10:08:411019browse

php 模板替换
如果 我要将模板文件的{$a}替换成 而不要把其他的{ok}这里面的替换 只替换有变量的 请问这样代码怎么实现? 把变量前面的替换我倒是知道 preg_replace('#{\s*\$#','
------解决方案--------------------

PHP code
$str='{$a}{ok}';echo preg_replace('#\{(\$\w+)\}#','<?php echo $1;?>',$str);<div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn