利用php查找替换函数更换标签实现前后端分离

发布时间 2023-04-18 18:34:38作者: paoPaoLong_liu
 1 <?php
 2 $name = "马大炮";
 3 $age  = 48;
 4 $str = file_get_contents("./view.html");
 5 $str = str_replace('{','<?php echo ',$str);
 6 $str = str_replace('}','?>',$str);  
 7 $str = file_put_contents("view.html",$str);
 8 include "./view.html";
 9 ?>
10 
11 
12 <!DOCTYPE html>
13 <html lang="en">
14 <head>
15     <meta charset="UTF-8">
16     <meta http-equiv="X-UA-Compatible" content="IE=edge">
17     <meta name="viewport" content="width=device-width, initial-scale=1.0">
18     <title>view.html 前端</title>
19 </head>
20 <body>
21     姓名:<?php echo $name?><br>
22     年龄:<?php echo $age?>
23 </body>
24 </html>