Php 在文件\u get\u contents()中传递变量

Php 在文件\u get\u contents()中传递变量,php,Php,我想在file\u get\u contents函数中传递一些变量 <?php extract($_POST); $html_content= file_get_contents("counties/indrsen/1.php"); $tenant_html=$first_name.' '.$last_name."_$new.html"; file_put_contents("3_day_notice_fad/$tenant_html",$html_content);

我想在file\u get\u contents函数中传递一些变量

  <?php
  extract($_POST);
  $html_content= file_get_contents("counties/indrsen/1.php");
  $tenant_html=$first_name.' '.$last_name."_$new.html";
  file_put_contents("3_day_notice_fad/$tenant_html",$html_content);
   ?>
其中1.php是简单的php文件,保存在countries/indrsen中。从上面的代码中,我调用1.php并希望将html文件保存在其他文件夹中,名称为3_day_notice_fad,带有变量。它正在文件夹中成功保存,但当我打开html文件时,它并没有以变量名显示

我想在文件中传递变量$first\u name和$last\u name\u put\u contents3\u day\u notice\u fad/$tenant\u html,$html\u content

1.php如下:

<p>To: Tenant's Name: <?php echo "$first_name.' '.$last_name"; ?> </p>
它显示html页面,如To:Tenant's Name:


但我希望使用类似于To:Tenant's Name:xyx jjj的值对其进行估价,谢谢大家的回复。我找到了答案

    ob_start();
    include('counties/indrsen/1.php');
    $html_content = ob_get_contents();
    ob_end_clean();

它工作正常。

eval也许-但请小心,因为“获取内容”不是模板引擎。它也不会运行php-code。请将您的.html重命名为.php,否则变量将永远无法编译。您还需要在新页面中声明变量。您需要在哪里定义$new?还是要将该变量写入文件中?后起源是未知的,它们的价值观也是未知的。问题不清楚,很好。谢谢。