Powered by Ajaxy
Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Analyser un format CSv: à revoir


{filelink=12996}

<?php
function parse_csv($string, $delim = ',', $quote='"')
{
    $new = str_replace("{$quote}{$quote}", $quote, $string);

    $matches = array();
    preg_match_all("/s*({$quote}?)(.*?)1s*(?:{$delim}|$)/",
        $new, $matches);

    array_pop($matches[2]);
    return $matches[2];
}

$str = 'c "s""v""","s", "f
y" ';

$values = parse_csv($str);

echo '<pre>';
print_r($values);
echo '</pre>';
?>

No comments yet.

Leave a Comment