62 const RIS_EOL =
"\r\n";
63 const LINE_REGEX =
'/^(([A-Z1-9]{2})\s+-(.*))|(.*)$/';
64 protected $data = NULL;
90 $flags = FILE_SKIP_EMPTY_LINES | FILE_TEXT;
91 $contents = file(
$filename, $flags, $context);
92 $this->parseArray($contents);
111 $contents = explode(RISReader::RIS_EOL, $string);
112 $this->parseArray($contents);
120 $recordset = array();
122 $this->cleanData($lines);
125 foreach ($lines as $line) {
128 preg_match(self::LINE_REGEX, $line, $matches);
129 if (! empty($matches[3])) {
130 $lastTag = $matches[2];
131 $record[$matches[2]][] = trim($matches[3]);
133 elseif (! empty($matches[2]) && $matches[2] ==
'ER') {
135 $recordset[] = $record;
137 } elseif (! empty($matches[4])) {
140 if (! empty($lastTag)) {
141 $lastEntry = count($record[$lastTag]) - 1;
144 $record[$lastTag][$lastEntry] .=
' ' . trim($matches[4]);
148 if (! empty($record)) {
149 $recordset[] = $record;
151 $this->data = $recordset;
161 $format =
"%s:\n\t%s\n";
162 foreach ($this->data as $record) {
163 foreach ($record as $key => $values) {
164 foreach ($values as $value) {
165 printf($format, RISTags::describeTag($key), $value);
188 if (substr($first, 0, 3) == pack(
'CCC', 0xef, 0xbb, 0xbf)) {
189 $lines[0] = substr($first, 3);