function biblio_strcsv in Bibliography Module 7
Same name and namespace in other branches
- 6.2 includes/biblio.import.export.inc \biblio_strcsv()
- 6 biblio.import.export.inc \biblio_strcsv()
- 7.2 includes/biblio.import.export.inc \biblio_strcsv()
1 call to biblio_strcsv()
- biblio_csv_export in includes/
biblio.import.export.inc
File
- includes/
biblio.import.export.inc, line 897 - Functions that are used to import and export biblio data.
Code
function biblio_strcsv($fields = array(), $delimiter = ',', $enclosure = '"') {
$str = '';
$escape_char = '\\';
foreach ($fields as $value) {
if (strpos($value, $delimiter) !== FALSE || strpos($value, $enclosure) !== FALSE || strpos($value, "\n") !== FALSE || strpos($value, "\r") !== FALSE || strpos($value, "\t") !== FALSE || strpos($value, ' ') !== FALSE) {
$str2 = $enclosure;
$escaped = 0;
$len = strlen($value);
for ($i = 0; $i < $len; $i++) {
if ($value[$i] == $escape_char) {
$escaped = 1;
}
elseif (!$escaped && $value[$i] == $enclosure) {
$str2 .= $enclosure;
}
else {
$escaped = 0;
}
$str2 .= $value[$i];
}
$str2 .= $enclosure;
$str .= $str2 . $delimiter;
}
else {
$str .= $value . $delimiter;
}
}
$str = substr($str, 0, -1);
$str .= "\n";
return $str;
}