0

我有一个 PHP 页面 (content.php),其中包含由 PHP 变量传递的纯 HTML 和内容

<html>
     <head>
     </head>
     <body>
          <h1><?php echo $title; ?></h1>
     </body>
</html>

然后是另一个 PHP 页面,我需要在字符串中包含 content.php 的内容,但已经由 PHP 解析器处理。我已经尝试了 file_get_contents() 函数,但这给出了原始输出(未处理 PHP)。我正在寻找的是:

$var contents = somefunction('contents.php')内容:

<html>
     <head>
     </head>
     <body>
          <h1>Title</h1>
     </body>
</html>

非常感谢任何帮助!

4

3 回答 3

1

尝试:

ob_start();
include ('contents.php');
$html = ob_get_clean();
ob_end_clean();
于 2013-02-06T09:56:27.590 回答
0

你试过include吗?或者,如果您需要从“外部”获取它(例如在浏览器中加载它),请使用file_get_contents完整的http://example.com/filename.phpURL。

于 2013-02-06T09:56:52.117 回答
0

要么我在这里严重遗漏了一些东西,要么在您的第二页中不使用函数,为什么不直接将内容分配给这样的字符串:

$my_String = "<html>
     <head>
     </head>
     <body>
          <h1>". $title ."</h1>
     </body>
</html>"; 
于 2013-02-06T10:05:34.780 回答