如下代码:
test.php<!--{{title}}=首页;{{author}}=测试;-->
<html>
<body>
<?php echo "The test data!";?>
</body>
</html>
比如我在test2.php中怎样能获得{{title}}的值 '首页'  呢?

解决方案 »

  1.   

    preg_match('/<\!{{title}}=(.+);{{author}}=测试;-->/', $s, $arr);
    echo '<pre>';print_r($arr);exit;//在家里,没安装php,没法帮你太多,以上可能需要修改下(正则半吊子)
      

  2.   

    $str = '<!--{{title}}=首页;{{author}}=测试;-->';//str可以file_get_contents来读取文件preg_match_all('/\{\{title\}\}=(.*?);/is', $str, $arr);print_r($arr);
      

  3.   


    $test = '<!--{{title}}=首页;{{author}}=测试;-->'#这里是你需要替换的字符串;
    $preg_match_all('|^\{{,2}([a-zA-Z_-]*)\}{,2}=(.*?);$|si',$test,$result);#$result是符合模式的字符串数组返回
    print_r($result);
    #有没有一种办法可以先抓取标识符 <!--$内容 --> 再递归抓取$内容中的所有内容 放进字符串 再用;截断
    #这样会抓取所有HTML注释内容 如果只是替换模板的话倒是我想多了