62 const RIS_EOL =
"\r\n";
63 const LINE_REGEX =
'/^(([A-Z1-9]{2})\s+-(.*))|(.*)$/';
89 $flags = FILE_SKIP_EMPTY_LINES | FILE_TEXT;
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;
161 foreach ($this->
data as $record) {
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);
parseFile($filename, $context=NULL)
Parse an RIS file.
parseString($string)
Parse a string of RIS data.
__construct($options=array())
parseArray($lines)
Take an array of lines and parse them into an RIS record.
The main class for parsing RIS files.
This is a library for parsing RIS files.
cleanData(&$lines)
Clean up the data before processing.