2014-10-10 40 views
-1

我想提出一个功能来下载我DB.Here邮件数据是我的代码:如何解决错误“致命错误:调用一个非对象的成员函数str_get_html()”?

include('simple_html_dom.php'); 
$html = new simple_html_dom(); 
global $html; 
function getArraySubject($stream,$subject){ 

$array = imap_search($stream, $subject); 
return $array ; 
} 
// $domain 0 = any domeain from which we are receiving mails 
//$case = subject number for ex :- Query, Potential..... 
function getDataFromHTML($subjectArray, $domain = 0, $case = 1) 
{ 
$completeArray = array(); 
if ($domain == 0 && $case == 1) { 
rsort($subjectArray); 

foreach($subjectArray as $email_id){ 

$body = imap_qprint(imap_body($stream,$email_id)); 
    $my_file = 'mail-data.txt'; 
    file_put_contents($my_file, $body); 
    $html = file_get_contents($my_file, true); 
    $htmlData = $html->str_get_html($body); 
    $tds = $htmlData->find('table',3)->find('td'); 
    $num = null; 
    $i = 0 ; 
    foreach($tds as $td){ 
     $completeArray['magicbricks']['case1'][$i] = $td->innertext; 
        $i++;   
      } 
} 
} 
return $completeArray; 
} 

我得到一个错误“致命错误:调用一个成员函数str_get_html()非对象上第25行“。

如何解决此问题?请帮忙。

这是我第二个文件,我在上面提到的函数。

error_reporting(E_ALL); 
ini_set('display_errors', 1); 
include('functions.php'); 
// Configure your imap mailboxes 
$mailboxes = array(
    array(
    'label'  => 'Label', 
    'mailbox' => '{imap.gmail.com:993/imap/ssl}INBOX', 
    'username' => '[email protected]', 
    'password' => 'abc246' 
) 
    ); 

foreach ($mailboxes as $current_mailbox) { 

// Open an IMAP stream to our mailbox 
$stream = @imap_open($current_mailbox['mailbox'], $current_mailbox['username'],  $current_mailbox['password']); 

if (!$stream) { 
?> 
    <p>Could not connect to: <?php echo $current_mailbox['label']?>. Error: <?php echo imap_last_error()?></p> 
<?php 
} else { 
    $sub1 = 'SUBJECT "Query" FROM "magicbricks.com"'; 


$array1 = getArraySubject($stream,$sub1); 

print_r($array1); 

    if (!count($array1)){ 
    ?> 
     <p>No e-mails found.</p> 
    <?php 
    } else { 

     $result = getDataFromHTML($array1, $domain = 0, $case = 1); 

print_r($result); 

    } 
    } 

    // Close our imap stream. 
    imap_close($stream); 

} // end foreach 

回答

2

在这种情况下最有可能$html是一个字符串,所以你不能任何方法附加到它:

$html = file_get_contents($my_file, true); // this is not an instance of simple-html-dom object 
$htmlData = $html->str_get_html($body); 
      ^

删除:

$htmlData = str_get_html($body); // now this create a simple-html-dom object 
+0

感谢,但现在它显示了同样的错误在下一行,即find() – shweta 2014-10-10 03:28:48

+0

@shweta'mail-data.txt'包含什么?一个html标记模板? – Ghost 2014-10-10 03:29:28

+0

它包含邮箱的完整数据,但即使删除这3行也没有效果。 $ my_file ='mail-data.txt'; file_put_contents($ my_file,$ body); $ html = file_get_contents($ my_file,true); – shweta 2014-10-10 03:31:58

0
include('simple_html_dom.php'); 
$html = new simple_html_dom(); 
global $html; //This is unnecessary 
function getArraySubject($stream,$subject){ 

$array = imap_search($stream, $subject); 
return $array ; 
} 
// $domain 0 = any domeain from which we are receiving mails 
//$case = subject number for ex :- Query, Potential..... 
function getDataFromHTML($subjectArray, $domain = 0, $case = 1) 
{ 

//Add this 
global $html; 


$completeArray = array(); 
if ($domain == 0 && $case == 1) { 
rsort($subjectArray); 

foreach($subjectArray as $email_id){ 

$body = imap_qprint(imap_body($stream,$email_id)); 
    $my_file = 'mail-data.txt'; 
    file_put_contents($my_file, $body); 
    $fileData = file_get_contents($my_file, true); //renamed this 
    $htmlData = $html->str_get_html($body); 
    $tds = $htmlData->find('table',3)->find('td'); 
    $num = null; 
    $i = 0 ; 
    foreach($tds as $td){ 
     $completeArray['magicbricks']['case1'][$i] = $td->innertext; 
        $i++;   
      } 
} 
} 
return $completeArray; 
} 
+0

:(没有用的,我是新的oops。你可以查询 $ body = imap_qprint(imap_body($ stream,$ email_id));我认为$ stream不能正常工作, – shweta 2014-10-10 05:51:51

+0

有人在吗? – shweta 2014-10-10 06:22:06

相关问题