Transform csv file into array data
@param string $filename
@param string $delimiter
@return array
776101
public static function csvFileToArray($filename='', $delimiter=',')
    {
        $header = null;
        $data = [];
        if (($handle = fopen($filename, 'r')) !== false) {
            while (($row = fgetcsv($handle, 1000, $delimiter)) !== false) {
                if (!$header) {
                    $header = $row;
                } else {
                    $data[] = array_combine($header, $row);
                }
            }
            fclose($handle);
        }

        return $data;
    }
406830
public static function convertCamel($str, $separators = ['_', '-'], $delimiter = '')
	{
		$str = ucwords(str_replace($separators, ' ', $str));

		return str_replace(' ', $delimiter, $str);
	}
1263382
protected function parseCsv($filename, ConfigurationInterface $config)
    {
        $length = $config->getLength();
        $delimiter = $config->getDelimiter();
        $enclosure = $config->getEnclosureChar();
        $escape = $config->getEscapeChar();
        $result = [];

        if (($handle = fopen($filename, 'r')) !== false) {
            while (($row = fgetcsv($handle, $length, $delimiter, $enclosure, $escape)) !== false) {
                $temp = [];

                if (empty($this->attributes)) {
                    if ($config->isFirstLineAsAttributes()) {
                        $this->attributes = $row;
                    } else {
                        $cRow = count($row);
                        for ($i = 0; $i < $cRow; ++$i) {
                            $attrName = 'attribute '.$i;
                            $this->attributes[] = $attrName;
                            $temp[$attrName] = trim($row[$i]);
                        }
                        $result[] = $temp;
                    }
                } else {
                    $cRow = count($row);
                    for ($i = 0; $i < $cRow; ++$i) {
                        $attrName = $this->attributes[$i];
                        $temp[$attrName] = trim($row[$i]);
                    }
                    $result[] = $temp;
                }
            }
            fclose($handle);
        }

        return $result;
    }
1074879
public function __tocsv($structure, $delimiter = ',', $enclosure = '"')
    {
        s()->async(true);

        ini_set('memory_limit', '2048M');

        // Output file from browser
        header('Content-Description: File Transfer');
        header('Content-Type: application/vnd.ms-excel; charset=utf-8');
        header('Content-Disposition: attachment; filename=Export'.date('dmY').'.csv');
        header('Expires: 0');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Pragma: public');

        // Write to php temp because php natively support csv files creation
        $handle = fopen('php://temp', 'r+');
        fputs($handle, chr(0xEF) . chr(0xBB) . chr(0xBF)); // UTF-8 BOM
        foreach ((new Table($structure))->toArray() as $line) {
            fputcsv($handle, $line, ';');
        }

        // Read file from temp
        rewind($handle);
        $csv = '';
        while (!feof($handle)) {
            $csv .= fread($handle, 8192);
        }
        fclose($handle);

        // Convert to Excel readable format
        echo mb_convert_encoding($csv, 'Windows-1251', 'UTF-8');
    }
733279
public static function readFileToArray($url, $delm = ";", $encl = "\"", $head = false)
    {
        $csvxrow = file($url); // ---- csv rows to array ----
        
        $csvxrow[0] = chop($csvxrow[0]);
        $csvxrow[0] = str_replace($encl, '', $csvxrow[0]);
        $keydata = explode($delm, $csvxrow[0]);
        $keynumb = count($keydata);
        $csv_data = array();
        $out = array();
        if ($head === true) {
            $anzdata = count($csvxrow);
            $z = 0;
            for ($x = 1; $x < $anzdata; $x ++) {
                $csvxrow[$x] = chop($csvxrow[$x]);
                $csvxrow[$x] = str_replace($encl, '', $csvxrow[$x]);
                $csv_data[$x] = explode($delm, $csvxrow[$x]);
                $i = 0;
                foreach ($keydata as $key) {
                    $out[$z][$key] = $csv_data[$x][$i];
                    $i ++;
                }
                $z ++;
            }
        } else {
            $i = 0;
            foreach ($csvxrow as $item) {
                $item = chop($item);
                $item = str_replace($encl, '', $item);
                $csv_data = explode($delm, $item);
                for ($y = 0; $y < $keynumb; $y ++) {
                    $out[$i][$y] = $csv_data[$y];
                }
                $i ++;
            }
        }
        
        return $out;
    }
335293
public function get($name, $delimiter = self::DELIMITER) {
		if (strpos($name, $delimiter) === false) {
			return isset($this->_data[$name])
				? $this->_data[$name]
				: null;
		}
		
		list ($first, $rest) = explode($delimiter, $name, 2);
		
		if (isset($this->_data[$first]) && $this->_data[$first] instanceof self) {
			return $this->_data[$first]->get($rest, $delimiter);
		}
	}
369419
public static function explode($string, $delimiter)
    {
        if (!String::isValid($string) ||
            String::isEmpty($string)) {
            return false;
        }

        return explode($delimiter, $string);
    }
125973
private function arrayToCsv(
        array &$fields,
        $delimiter,
        $enclosure,
        $encloseAll = false,
        $nullToMysqlNull = false
    ) {
        $delimiterEsc = preg_quote($delimiter, '/');
        $enclosureEsc = preg_quote($enclosure, '/');

        $output = [];
        foreach ($fields as $field) {
            if ($field === null && $nullToMysqlNull) {
                $output[] = 'NULL';
                continue;
            }

            // Enclose fields containing $delimiter, $enclosure or whitespace
            if ($encloseAll
                || preg_match(
                    "/(?:$delimiterEsc|$enclosureEsc|\s)/",
                    $field
                )
            ) {
                $output[] = $enclosure . str_replace(
                    $enclosure,
                    $enclosure . $enclosure,
                    $field
                ) . $enclosure;
            } else {
                $output[] = $field;
            }
        }

        return implode($delimiter, $output) . "\n";
    }
497439
protected static function stringToArray(
        string $delimiter,
        int $limit = PHP_INT_MAX,
        RuleInterface $next = null
    ): RuleInterface {
        return $next === null ?
            new StringToArray($delimiter, $limit) : new AndOperator(new StringToArray($delimiter, $limit), $next);
    }
1066864
public static List<String> readUniqueColumnValuesFromDelimitedFile(String filename, 
      int columnNumber, String delimiter) {
    Set<String> values = Sets.newHashSet(
        readColumnFromDelimitedFile(filename, columnNumber, delimiter));
    return Lists.newArrayList(values);
  }
727856
public static function csvToArray($file, $param = array(
        'length' => 0,
        'delimiter' => ';',
        'enclosure' => '"',
        'escape' => '\\',
        'skipFirstRow' => false,
        'indexFromFirstRow' => false
    ))
    {

        $defParam = array(
            'length' => 0,
            'delimiter' => ';',
            'enclosure' => '"',
            'escape' => '\\',
            'skipFirstRow' => false,
            'indexFromFirstRow' => false
        );

        $param = array_merge($defParam, $param);

        $handle = fopen($file, 'r');

        $data = array();

        $first = true;
        $index = false;

        while (($line = fgetcsv($handle, $param['length'], $param['delimiter'], $param['enclosure'], $param['escape'])) !== FALSE) {
            if ($first) {
                if ($param['indexFromFirstRow']) {
                    $index = $line;
                }
            }

            if ($param['indexFromFirstRow'] && !$first || ($param['indexFromFirstRow'] && $param['skipFirstRow'] !== true)) {

                $newline = array();

                foreach ($line as $key => $value) {
                    if (isset($index[$key])) {
                        $newline[$index[$key]] = $value;
                    } else {
                        $newline[] = $value;
                    }
                }
                $data[] = $newline;
            } elseif (!$first || ($first && $param['skipFirstRow'] !== true)) {
                $data[] = $line;
            }

            $first = false;
        }

        fclose($handle);

        return $data;
    }
280238
protected function fputcsv($filePointer, $dataArray, $delimiter = ",",   $enclosure = "\"")
  {
    // Build the string
    $string = "";
    // No leading delimiter
    $writeDelimiter = false;
    foreach ($dataArray as $dataElement) {
      // Replaces a double quote with two double quotes
      $dataElement = str_replace("\"", "\"\"", $dataElement);
      // Adds a delimiter before each field (except the first)
      if ($writeDelimiter) {
        $string .= $delimiter;
      }
      // Encloses each field with $enclosure and adds it to the string
      if ($enclosure) {
        $string .= $enclosure . $dataElement . $enclosure;
      } else {
        $string .= $dataElement;
      }
      // Delimiters are used every time except the first.
      $writeDelimiter = true;
    }
    // Append new line
    $string .= "\n";
    // Write the string to the file
    fwrite($filePointer, $string);
  }
1086857
public function parse( $data = null, $type = null, $delimiter = null ) {

		if ( ! empty( $data ) ) {
			$this->input = $data;
		}

		if ( ! empty( $type ) && in_array( $type, $this->types, true ) ) {
			$this->type = $type;
		}

		if ( !empty( $delimiter ) )
			$this->delimiter = $delimiter;

		if ( method_exists( $this, "parse_{$this->type}" ) ) {
			return call_user_func( array( $this, 'parse_' . $this->type ) );
		}

		return $this->parsed;
	}
33434
public static function explode($delimiter, $string, $limit = null) {
        if (empty($string)) return [];
        return explode($delimiter, $string, $limit);
    }
751125
public static String[] buildArrayWithDelimiter(String stringWithDelimiter,
            String delimiter) {
        return toArray(JMCollections
                .buildListWithDelimiter(stringWithDelimiter, delimiter));
    }
1047747
public static function unflatten(array $array, $delimiter = '.')
    {
        $unflattenedArray = array();

        foreach ($array as $key => $value) {
            $keyList  = explode($delimiter, $key);
            $firstKey = array_shift($keyList);

            if (sizeof($keyList) > 0) {
                $subArray = static::unflatten(array( implode($delimiter, $keyList) => $value ), $delimiter);

                foreach ($subArray as $subArrayKey => $subArrayValue) {
                    $unflattenedArray[ $firstKey ][ $subArrayKey ] = $subArrayValue;
                }
            } else {
                $unflattenedArray[ $firstKey ] = $value;
            }
        }

        return $unflattenedArray;
    }
179774
public function toString($delimiter = ' ') {
        $queryFieldString = '';

        foreach ($this->queryFields as $fieldName => $fieldBoost) {
            $queryFieldString .= $fieldName;

            if ($fieldBoost != 1.0) {
                $queryFieldString .= '^' . number_format($fieldBoost, 1, '.', '');
            }

            $queryFieldString .= $delimiter;
        }

        return rtrim($queryFieldString, $delimiter);
    }