PHP 8.1.33
Preview: Csvreader.php Size: 1.74 KB
/home/jambtst2015/public_html/protected/extensions/Csvreader.php

<?php
/**
 * CCsvreader class file.
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @link http://www.yiiframework.com/
 * @copyright 2008-2013 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */
class Csvreader extends CController
{
	
	var $fields;            /** columns names retrieved after parsing */
    var $separator = ',';    /** separator used to explode each line */
    var $enclosure = '"';    /** enclosure used to decorate each field */

    var $max_row_size = 4096;    /** maximum row size to be used for decoding */
	
	public static function parse_file($p_Filepath, $p_NamedFields = true) {
        $content = false;
        $file = fopen($p_Filepath, 'r');
        if($p_NamedFields) {
            $this->fields = fgetcsv($file, $this->max_row_size, $this->separator, $this->enclosure);
        }
        while( ($row = fgetcsv($file, $this->max_row_size, $this->separator, $this->enclosure)) != false ) {
            if( $row[0] != null ) { // skip empty lines
                if( !$content ) {
                    $content = array();
                }
                if( $p_NamedFields ) {
                    $items = array();

                    // I prefer to fill the array with values of defined fields
                    foreach( $this->fields as $id => $field ) {
                        if( isset($row[$id]) ) {
							$field = str_replace(" ","_",strtolower($field));
                            $items[$field] = trim($row[$id]);
                        }
                    }
                    $content[] = $items;
                } else {
                    $content[] = $row;
                }
            }
        }
        fclose($file);
        return $content;
    }
	
	
}

Directory Contents

Dirs: 2 × Files: 7

Name Size Perms Modified Actions
yii-mail DIR
- drwxr-xr-x 2025-10-09 04:11:14
Edit Download
- drwxr-xr-x 2024-11-22 17:53:11
Edit Download
81 B lr--r--r-- 2024-12-09 06:09:12
Edit Download
1.74 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
9.75 KB lrw-r--r-- 2025-11-03 23:01:39
Edit Download
11.84 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
65.71 KB lr--r--r-- 2024-04-12 06:09:12
Edit Download
935.79 KB lrwxrwxrwx 2024-11-22 17:53:11
Edit Download
84.30 KB lrwxrwxrwx 2024-11-22 17:53:11
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).