meine Frage war:
Zwischenzeitlich habe ich selbst was geschrieben:gibt es irgendwo eine fertige Funktion für csv-Zeilen wie z.B.:
Code: Alles auswählen
// getcsv ($var, $Trennzeichen, $Texterkennungszeichen, $Texterkennungszeichen_löschen) getcsv($string, ";", '"');
Code: Alles auswählen
<?php
function getcsv($var, $delimiter=';', $field_delimiter='"', $rfd=false)
{
// standard: '#("[^"]*"|[^";]+)#'
$pattern = '#(' . $field_delimiter . '[^' . $field_delimiter . ']*' . $field_delimiter . '|[^' . $field_delimiter . '' . $delimiter . ']+)#';
preg_match_all($pattern, $var, $matches);
$matches = $matches[1];
if ( $rfd )
{
$matches = str_replace($field_delimiter, '', $matches);
}
return $matches;
}
$var = '"text1";"text2";"text3;text4;text5";0.00;"text6";10;1234;"text7";text8;"";"text9";"";"text10"';
echo('<pre>');
print_r(getcsv($var, ';', '"'));
print_r(getcsv($var, ';', '"', true));
echo('</pre>');
?>
Code: Alles auswählen
Array
(
[0] => "text1"
[1] => "text2"
[2] => "text3;text4;text5"
[3] => 0.00
[4] => "text6"
[5] => 10
[6] => 1234
[7] => "text7"
[8] => text8
[9] => ""
[10] => "text9"
[11] => ""
[12] => "text10"
)
Array
(
[0] => text1
[1] => text2
[2] => text3;text4;text5
[3] => 0.00
[4] => text6
[5] => 10
[6] => 1234
[7] => text7
[8] => text8
[9] =>
[10] => text9
[11] =>
[12] => text10
)
Gruß