PHP包括HTML文件

时间:2012-09-13 19:24:33

标签: php wordpress include slideshow

我需要在PHP文件中包含一个HTML文件。 HTML文件包含以下内容:

  <div id="slideshow">
    <ul>
      <li>
        <img src="http://farm6.static.flickr.com/5270/5627221570_afdd85f16a_z.jpg" alt="" title="Light Trails" />
      </li>

      <li>
        <img src="http://farm6.static.flickr.com/5146/5627204218_b83b2d25d6_z.jpg" alt="" title="Bokeh" />
      </li>

      <li>           
        <img src="http://farm6.static.flickr.com/5181/5626622843_783739c864_z.jpg" alt="" title="Blossoms" />
      </li>

      <li>           
        <img src="http://farm6.static.flickr.com/5183/5627213996_915aa49939_z.jpg" alt="" title="Funky Painting" />
      </li>

      <li>           
        <img src="http://farm6.static.flickr.com/5182/5626649425_fde8610329_z.jpg" alt="" title="Vintage Chandelier" />
      </li>                          
    </ul>
  </div>   

  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
  <script src="/slideshow/js/craftyslide.min.js"></script>

  <script>
    $("#slideshow").craftyslide();
  </script>

要包含我正在使用此PHP语句的HTML文件:

<?php include ('http://nicksgroent.dk/slideshow/demo.html' ); ?>

然而这不起作用。

4 个答案:

答案 0 :(得分:3)

<?php echo file_get_contents('http://nicksgroent.dk/slideshow/demo.html'); ?>

答案 1 :(得分:1)

您可能已关闭远程包含。 (allow_url_include)但是,根据链接,这不是包含远程文件的理想方式。你最好使用file_get_contents或CURL。

请参阅https://stackoverflow.com/a/1158392/1324019

答案 2 :(得分:0)

如果启用了allow_fopen_url

$content = file_get_contents('http://nicksgroent.dk/slideshow/demo.html');
echo $content;

或卷曲

$ch = curl_init('http://nicksgroent.dk/slideshow/demo.html');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$content = curl_exec($ch);
curl_close($ch);
echo $content;

答案 3 :(得分:0)

包括预期php文件和解析,尝试以下内容;

$page = file_get_contents('http://nicksgroent.dk/slideshow/demo.html');
echo $page;