请选择 进入手机版 | 继续访问电脑版

smarty框架生成简单的混编文件案例代码

[复制链接]
查看2132 | 回复0 | 2020-11-25 11:31 | 显示全部楼层 |阅读模式
smarty框架生成简单的混编文件案例代码
php代码:
  1. <?php
  2. $title='锄禾';
  3. $str=file_get_contents('./index.html');
  4. $str=str_replace('{','<?php echo ',$str);        //替换左大括号
  5. $str=str_replace('}',';?>',$str);                        //替换右大括号
  6. file_put_contents('./index.html.php', $str);        //写入混编文件
  7. require './index.html.php';        //包含混编文件
复制代码
html代码:
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>无标题文档</title>
  6. </head>

  7. <body>
  8. {$title}
  9. </body>
  10. </html>
复制代码

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

UID
1
贡献
387
丢币
38902
主题
4607
回帖
116
注册时间
2018-9-25
最后登录
2024-3-24