Jump to content

Using fetchbody in loadHTML


Recommended Posts

Hi all

 

I'm managing to get the HTML content from an email body using

$html = quoted_printable_decode(imap_fetchbody($inbox,$email_number,1));

and when I print $html it displays the correct email html code.

 

But when I try and use it (line 2)

$doc = new DOMDocument();
$doc->loadHTML($html);
$xpath = new DOMXPath($doc);
$tables = $doc->getElementsByTagName('table');

$nodes  = $xpath->query('.//tbody/tr/td', $tables->item(5));
print $nodes->item(3)->nodeValue;

I get the error

 

Notice: Trying to get property of non-object

 

Do I need to clean up the $html variable before it can be used?

 

Thanks for any advice

Link to comment
Share on other sites

What property? What non-object? We need the actual line, not just the error message.

 

You have a total lack of error handling, so that's likely the reason for the notice. You cannot just assume that all HTML selectors and queries will yield a non-empty result. You have to actually check that before you can start processing the result.

 

It's also time to learn basic debugging skills like inspecting variables with var_dump(). We can speculate all day long about what might be wrong, but if you want a definite answer, you have to analyze the data and control flow.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.