Reading xls (Excel) files in PHP
<p>I'm fairly new to this so I wanted to ask a question. I uploaded an excel file using html and when I try to learn how to read excel files using php, this is what I've got from IBM</p>

<pre><code>    &lt;?php
    $filename = basename($_FILES["file"]["name"]);

    $ext = substr($filename, strrpos($filename, '.') + 1);

    function get_data($qnum, $qtype, $qname, $qtext, $atext, $pcredit, $rcounts, $r, $qcount, $cfac, $sd, $disc_inx, $disc_coef){
        global $data;

        $data[] = array('QNum'=&gt;$qnum, 'Qtype'=&gt;$qtype, 'Questionname'=&gt;$qname, 'Questiontext'=&gt;$qtext, 
'Answertext'=&gt;$atext, 'PartialCredit'=&gt;$pcredit, 'RCounts'=&gt;$r, 'QCount'=&gt;$qcount, 
'Correctionfacility'=&gt;$cfac, 'DiscriminationIndex'=&gt;$disc_inx, 'DiscriminationCoefficient'=&gt;$disc_coef);
    }

            if($ext == "xls"){
                $dom = DOMDocument::load($_FILES['file']['tmp_name']);
                $rows = $dom-&gt;getElementsByTagName('Row');
                $first_row = true;
                foreach($rows as $row){
                 if(!$first_row){
                $qnum = "";
                $qtype = "";
                $qname = "";
                $qtext = "";
                $atext = "";
                $pcredit = "";
                $r = "";
                $qcount = "";
                $cfac = "";
                $disc_inx = "";
                $disc_coef = "";

                $index = 1;
                $cells = $row-&gt;getElementsByTagName('Cell');
                foreach($cells as $cell){
                    $ind = $cell-&gt;getAttribute('Index');
                    if($ind != null) $index = $ind;

                    if($index == 1) $qnum = $cell-&gt;nodeValue;
                        if($index == 2) $qtype = $cell-&gt;nodeValue;
                    if($index == 3) $qname = $cell-&gt;nodeValue;
                    if($index == 4) $qtext = $cell-&gt;nodeValue;
                    if($index == 5) $atext = $cell-&gt;nodeValue;
                    if($index == 6) $pcredit = $cell-&gt;nodeValue;
                    if($index == 7) $r = $cell-&gt;nodeValue;
                    if($index == 8) $qcount = $cell-&gt;nodeValue;
                    if($index == 9) $cfac = $cell-&gt;nodeValue;
                    if($index == 10) $disc_inx = $cell-&gt;nodeValue;
                    if($index == 11) $disc_coef = $cell-&gt;nodeValue;

                    $index += 1;
                }
                get_data($qnum, $qtype, $qname, $qtext, $atext, $pcredit, $r, $qcount, $cfac, $disc_inx, $disc_coef);
            }
            $first_row = false;
        }
    }

    else{
        echo "Invalid file!";
    }
    ?&gt;
</code></pre>

<p>And I got a syntax error Warning: DOMDocument::load(): Start tag expected, '&lt;' not found in /tmp/phpwUIpyZ, line: 1 in /var/www/moodle/question/upload_file.php on line 16 Fatal error: Call to a member function getElementsByTagName() on a non-object in /var/www/moodle/question/upload_file.php on line 17. What is the error on my code? Need help please thanks!!</p>
