file_get_contents需要php的内容!我需要在HTML代码中的源代码

问题描述:

我试图把我的.php文件的html内容与file_get_contents,但我无法管理它。无论我做什么,它都需要.php内容,所以我希望你能理解并能帮助我。file_get_contents需要php的内容!我需要在HTML代码中的源代码

的脚本代码:

 <?php 
      $homepageheader = file_get_contents('xxx/1header.php'); 
      $homepage2 = file_get_contents('xxx/4.php'); 
      $homepage3 = file_get_contents('xxx/3.php'); 
      $homepage4 = file_get_contents('xxx/2.php'); 
      $homepagefooter = file_get_contents('xxx/5footer.php');       $spinnercontent = file_get_contents('spinnercontent.php'); 

    if ($content_type == '1') { 

    $linkcontent = " 

    $homepageheader 


    $homepage2<br> 
    $homepage3<br> 
    $homepage4<br> 
    $homepagefooter 
    "; 
    }else{ 
    $linkcontent = " 
      $homepageheader 
      $spinnercontent 
      $homepagefooter 
    "; 

spinnercontent.php代码:

<?php 
$first = 'xxx/2.php'; 
$second = 'xxxx/3.php'; 
$third = 'xxx/4.php'; 
$four = 'xxx/5.php'; 

$homapagespinner = array($first, $second, $third, $four); 
shuffle($homapagespinner); 

foreach($homapagespinner as $el) { 
    include($el); 
} 
?> 
+2

'file_get_contents'从字面上获取文件内容。如果你想让它们运行并得到结果,使用'include' ... *就像你已经*在你的'foreach'里面一样。 –

+0

是'include()'或'file_get_contents('http://host.com/xxx/1header.php');'如果允许。 – AbraCadaver

+0

不清楚你想要做什么。如果你想获得php输出,“xxx”部分应该包含http://。如果你想包含一个php源代码,使用include – Ghigo

如果你想在一个字符串的输出,你可以使用下面的代码:

ob_start(); 
include '/path/to/file.php'; 
$content = ob_get_clean();