Coseva\CSV::toTable PHP Method

toTable() public method

This is a great way to display the filtered contents of the csv to you during the development process (for debugging purposes).
public toTable ( ) : string
return string $output HTML table of CSV contents
    public function toTable()
    {
        $output = '';
        if (!isset($this->_rows)) {
            $this->parse();
        }
        if (!empty($this->_rows)) {
            // Begin table.
            $output = '<table border="1" cellspacing="1" cellpadding="3">';
            // Table head.
            $output .= '<thead><tr><th>&nbsp;</th>';
            foreach ($this->_rows as $row) {
                foreach ($row as $key => $col) {
                    $output .= '<th>' . $key . '</th>';
                }
                break;
            }
            $output .= '</tr></thead>';
            // Table body.
            $output .= '<tbody>';
            foreach ($this->_rows as $i => $row) {
                $output .= '<tr>';
                $output .= '<th>' . $i . '</th>';
                foreach ($row as $col) {
                    $output .= '<td>' . $col . '</td>';
                }
                $output .= '</tr>';
            }
            $output .= '</tbody>';
            // Close table.
            $output .= '</table>';
        }
        return $output;
    }