2

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

Dolph
  • 49,714
  • 13
  • 63
  • 88
saif
  • 43
  • 6

3 Answers3

4

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
  • 49,714
  • 13
  • 63
  • 88
  • @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 Jul 11 '10 at 18:24
  • I agree, relative paths are ok :) – Maerlyn Jul 11 '10 at 18:37
  • @Maerlyn: I didn't mean to suggest the OP switch to absolute paths. See the clarification at the bottom of my answer. – Dolph Jul 11 '10 at 19:53
  • Thanks a lot... that solved my problems, but one more thing the div iam fetching is all images & logos and it is displaying in one row........ and i want to format it in a 3/3 grid.....how to go about that. – saif Jul 12 '10 at 07:25
  • You need to open a new question :) – Dolph Jul 12 '10 at 14:11
1

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
  • 196
  • 2
  • 11
0

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';

gaRex
  • 4,144
  • 25
  • 37
  • 1
    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 Jul 11 '10 at 18:22