【问题标题】:How to use include_once in Apache/PHP?如何在 Apache/PHP 中使用 include_once?
【发布时间】:2014-05-21 14:59:01
【问题描述】:
  • 我的开发环境是:Win7,XAMPP 1.8.3.3 VC11。
  • 我的 PHP.ini 文件中的include_path 是:".;C:\xampp\php\PEAR"

我已经下载了一个包 simplehtmldom_1_5 并保存在“C:\xampp\php\PEAR”文件夹中,以便我的测试文件“C:\xampp\htdocs\test1.php”可以包含这个包中的 PHP 文件。我的 test1.php 看起来像:

<?php
include_once('simplehtmldom_1_5/simple_html_dom.php');
echo file_get_html('www.google.com')->plaintext;
?>

只要我输入http://localhost/test1.php,我就会收到以下错误:

Warning: file_get_contents(www.google.com): failed to open stream: No such file or directory in C:\xampp\php\pear\simplehtmldom_1_5\simple_html_dom.php on line 75

Notice: Trying to get property of non-object in C:\xampp\htdocs\test1.php on line 15

如果我将 simplehtmldom_1_5 包从“C:\xampp\php\PEAR”移动到“C:\xampp\htdocs\simplehtmldom_1_5”,然后尝试上面的 test1.php,我会收到以下错误:

Warning: file_get_contents(www.google.com): failed to open stream: No such file or directory in C:\xampp\htdocs\simplehtmldom_1_5\simple_html_dom.php on line 75

Notice: Trying to get property of non-object in C:\xampp\htdocs\test1.php on line 15

我花了相当多的时间来调试它,但现在放弃了。请帮助我哪里错了。

【问题讨论】:

    标签: php apache xampp include-path


    【解决方案1】:

    当使用file_get_contents 或类似函数打开 URL 时,您应该指定完整的协议来告诉 PHP 这是 Web 地址或外部文件而不是本地文件。

    因此,

    file_get_contents('www.google.com')
    

    应改为:

    file_get_contents('http://www.google.com');
    

    【讨论】:

      【解决方案2】:

      您可能指的是http://www.google.com,而不是一个名为www.google.com文件

      【讨论】:

        【解决方案3】:

        你需要使用 http:// 和 url

        <?php
        include_once('simplehtmldom_1_5/simple_html_dom.php');
        echo file_get_html('http://www.google.com')->plaintext;
        ?>
        

        您还需要检查 test1.php 所在的位置是否有文件 dir(simplehtmldom_1_5) 喜欢:-

        C:\xampp\htdocs\simplehtmldom_1_5
        

        【讨论】:

          猜你喜欢
          • 2016-04-28
          • 1970-01-01
          • 2012-02-23
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2023-03-11
          • 2018-12-02
          • 2016-02-24
          相关资源
          最近更新 更多