CSV parser function

/**
 * CSV 行を値の list に変換します
 * @author mimic28号
 * @param string csv
 * @param string terminator_char 区切文字を指定可能 default ,
 * @param string qq 値に含まれる " を指定可能 '""' もしくは、'\\"'
 * @return array
 */
function csv2values($csv ,$terminator_char = ',' ,$qq = null){
	$values = array();
	$tmp = preg_replace('/(?:\x0D\x0A|[\x0D\x0A])?$/' ,$terminator_char ,$csv ,1);

	if(isset($qq)){
		preg_match_all('/("[^"]*(?:' . $qq . '[^"]*)*"|[^' . $terminator_char . ']*)' . $terminator_char . '/' ,$tmp ,$matches);
	}
	else{
		preg_match_all('/("[^"]*"|[^' . $terminator_char . ']*)' . $terminator_char . '/' ,$tmp ,$matches);
	}

	for($i = 0; $i<count($matches[1]); $i++){
		if(preg_match('/^"(.*)"$/s' ,$matches[1][$i] ,$m)){
			$matches[1][$i] = $m[1];
		}

		$values[] = $matches[1][$i];
	}

	return $values;
}

mimic28号でした。