2
<?php
include 'simple_html_dom.php';
$url = 'http://en.wikipedia.org/wiki/Myst';
$html = file_get_html($url);
echo $html->find('body');
?>

This has been returning "Array" on the browser when I try to ONLY get the contents of the body element

2 Answers 2

3

Yes, because there may be many elements that fit that selector, so an array of elements is returned. If you only want the first matching element, use $html->find('body', 0). This is all described in the manual: http://simplehtmldom.sourceforge.net/manual.htm

Sign up to request clarification or add additional context in comments.

2 Comments

this html doesn't have an iframe...are there sometimes more than one body ?? sorry if this is a stupid question
@Praneet No, there should never be more than one <body>, but the find() method doesn't know or care. Any selector may match more than one element. That the specific selector 'body' should never match more than one element is irrelevant. What should find() do? If there's only one match, return that one match, otherwise return an array? That'd make your code more complicated since you'd always have to check whether it returned an array or an element. So, it's always returning an array.
0

Maybe try

echo $html->find('body', 0);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.