62 const RIS_EOL =
"\r\n";
63 const LINE_REGEX =
'/^(([A-Z1-9]{2})\s+-(.*))|(.*)$/';
65 protected $data = NULL;
89 $flags = FILE_SKIP_EMPTY_LINES | FILE_TEXT;
90 $contents = file(
$filename, $flags, $context);
92 $this->parseArray($contents);
109 $contents = explode (RISReader::RIS_EOL, $string);
110 $this->parseArray($contents);
117 $recordset = array();
120 $this->cleanData($lines);
124 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]);
134 elseif (!empty($matches[2]) && $matches[2] ==
'ER') {
136 $recordset[] = $record;
139 elseif (!empty($matches[4])) {
142 if (!empty($lastTag)) {
143 $lastEntry = count($record[$lastTag]) - 1;
146 $record[$lastTag][$lastEntry] .=
' ' . trim($matches[4]);
150 if (!empty($record)) $recordset[] = $record;
152 $this->data = $recordset;
160 $format =
"%s:\n\t%s\n";
161 foreach ($this->data as $record) {
162 foreach ($record as $key => $values) {
163 foreach ($values as $value) {
164 printf($format, RISTags::describeTag($key), $value);
180 if (empty($lines))
return;
187 if (substr($first, 0, 3) == pack(
'CCC', 0xef, 0xbb, 0xbf)) {
188 $lines[0] = substr($first, 3);