0

I need to extract a data on my site from another site but data can be extract but this error show which are mention in below.

Notice: Undefined offset: 1 in D:\xampp\htdocs\simplehtmldom\index.php on line 26

Please help me to solve out this problem. I am really greatful for your valuable answer.

My code is

<?php
    include('simplehtmldom/simple_html_dom.php');

    $html = new simple_html_dom();

    $html->load_file("http://www.nepalstock.com/companydetail.php");
    if (!empty($html)){
        $table = $html->find('table[width="100%"]');
    }
    if(!empty($table)){
        $i = 0;
        $data = array();
        foreach ($table[0]->find('tr') as $tr) {

            $i++;
            if ($i == 1 || $i == 2) continue;
            $td = $tr->find('td');

            array_push($data, array(
                'paid_up_value' => trim($td[0]->plaintext),
                'total_paid_up_value' => trim($td[1]->plaintext),  //This is my line 26
                'closing_market_price' => trim($td[2]->plaintext),
                'market_capitalization' => trim($td[3]->plaintext),
                'market_capitalization_date' => trim($td[4]->plaintext),
                'previous_closed'=>trim($td[5]->plaintext)
                )
            );
        }

    }    

    $html->clear();
    unset($html);

    if (empty($data)) exit('No data !!!');
    print '<pre>';
    print_r($data);
    print '</pre>';
?>
pau cha
  • 132
  • 8
  • try to check it first using `isset($td[1]->plaintext)`, and try to `var_dump($table)`, what is the output ? – Eko Junaidi Salam Apr 12 '15 at 11:03
  • Try var_dump($td[1]), and see what you get. It looks like this isn't a PHP object. – Amar Syla Apr 12 '15 at 11:32
  • ^^ Actually, `var_dump($td);` The entire object returned from `find()` is not what you expect it to be, and you don't do anything to validate it before the `array_push()` call. You'll need some error check after `$tr->find('td')` to ensure `$td` has the expected value. – Michael Berkowski Apr 12 '15 at 11:50
  • 1
    try this `array_push($data, array( 'currency' => preg_replace('/\s+/', ' ', trim($td[0]->plaintext)),Listed Shares 'paid_up_value' => @trim($td[0]->plaintext), 'total_paid_up_value' => @trim($td[1]->plaintext), 'closing_market_price' => @trim($td[2]->plaintext), 'market_capitalization' => @trim($td[3]->plaintext), 'market_capitalization_date' => @trim($td[4]->plaintext), 'previous_closed'=> @trim($td[5]->plaintext), )); ` – Sujan Shrestha Apr 15 '15 at 07:15
  • Thank you sujan for your comment. – pau cha Apr 15 '15 at 07:23

0 Answers0