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>