views:

58

answers:

3

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

+4  A: 

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.

Dolph
absolute paths are bad, it makes your code unportable
Maerlyn
@Maerlyn: To still ensure portability you may defined a constant in the index.php file, e.g. `const ROOT = __DIR__;`. But imho relative paths are absolutely okay, at least I never had problems with them ;)
nikic
I agree, relative paths are ok :)
Maerlyn
@Maerlyn: I didn't mean to suggest the OP switch to absolute paths. See the clarification at the bottom of my answer.
Dolph
saif
You need to open a new question :)
Dolph
+1  A: 

require and include paths can be tricky in PHP. Try to use full paths when you can. You'll find $_SERVER['DOCUMENT_ROOT'] usefull for that.

Activist
A: 

Your inlude_path should contain ".", which means current directory.

But if you having troubles with including file by relative name, then just try to use absolute names, like require_once('E:\wamp\www\in.com\components\simple_html_dom.php');

But better it should be:

require_once 'E:/wamp/www/in.com/components/simple_html_dom.php';

Alexander
No, you don't need to have `.` in the `include_path`. PHP takes `include_path` only into account if the path is neither a stream wrapper, nor absolute, nor relative (and it is relative in this case.)
nikic