Search code examples
phpincluderequire-once

Warning and Fatal error calling require_once()


I want to fetch div element from other website .

on which iam having my profile, i have tried using this code.

require_once('../simple_html_dom.php');

$html=file_get_html('http://www.example.com');
$ret=$html->find("div[id=frame-gallery]");
$ret=array_shift($ret);
echo($ret);

but this code is giving errors

Warning: require_once(../simple_html_dom.php) [function.require-once]: failed to open stream: No such file or directory in E:\wamp\www\in.com\components\com_content\view.php on line 22

Fatal error: require_once() [function.require]: Failed opening required '../simple_html_dom.php' (include_path='.;./includes;./pear') in E:\wamp\www\in.com\components\com_content\view.php on line 22

iam stuck with this plz help me with the code snippets for fetching the specific div element from a website


Solution

  • The file simple_html_dom.php is not where you're telling PHP to look for it.

    require_once('../simple_html_dom.php');
    

    To be safe, try using the full path instead of a relative path.

    require_once('E:\wamp\www\in.com\components\simple_html_dom.php');
    

    BTW, if the full path above is incorrect, then that is your problem. This is the path that PHP is trying.

    To clarify: I'm only suggesting the OP switch to absolute paths to identify and confirm the source of the issue. Going to production with absolute paths is rarely a good idea.