aboutsummaryrefslogtreecommitdiff
path: root/bibtex.php
diff options
context:
space:
mode:
Diffstat (limited to 'bibtex.php')
-rw-r--r--bibtex.php31
1 files changed, 31 insertions, 0 deletions
diff --git a/bibtex.php b/bibtex.php
index 13796e9..7f36063 100644
--- a/bibtex.php
+++ b/bibtex.php
@@ -185,6 +185,37 @@ class BibtexParser
}
+ /*
+ * Export sorted BiBTeX.
+ * Do not use after $this->expand_years()
+ *
+ */
+ public function export()
+ {
+ $res = '';
+ $this->sort();
+ foreach ($this->STRINGS as $key => $value)
+ {
+ $res .= '@STRING (' . $key . '="' . $value . '")' . "\n";
+ }
+
+ $res .= "\n\n";
+
+ foreach ($this->ENTRIES as $ent)
+ {
+ $res .= '@' . mb_strtoupper($ent['entry']) . ' {' . $ent['id'] . ",\n";
+ $fields = array();
+ foreach($ent as $key => $value)
+ {
+ // Skip our special fields
+ if (!in_array($key, array('id', 'entry')))
+ $fields[] = mb_strtoupper($key) . '=' . $value;
+ }
+ $res .= implode(",\n", $fields);
+ $res .= "\n}\n\n";
+ }
+ return $res;
+ }
}