You are here

public function File::_next in Bibliography Module 7

Same name and namespace in other branches
  1. 6.2 modules/marcParse/php-marc.php \File::_next()
  2. 6 marcParse/php-marc.php \File::_next()
  3. 7.2 modules/marcParse/php-marc.php \File::_next()

Return the next raw MARC record.

Returns th nexts raw MARC record from the read file, unless all records already have been read.

Return value

string|FALSE Either a raw record or False

1 call to File::_next()
File::next in modules/marcParse/php-marc.php
Return next Record-object.

File

modules/marcParse/php-marc.php, line 172
@package PHP-MARC

Class

File
Class File Class to read MARC records from file(s)

Code

public function _next() {

  /**
   * Exit if we are at the end of the file
   */
  if ($this->pointer >= count($this->raw)) {
    return FALSE;
  }

  /**
   * Read next line
   */
  $usmarc = $this->raw[$this->pointer++];

  // Remove illegal stuff that sometimes occurs between records
  // preg_replace does not know what to do with \x00, thus omitted.
  $usmarc = preg_replace("/^[\n\r]+/", "", $usmarc);

  /**
   * Record validation
   */
  if (strlen($usmarc) < 5) {
    $this
      ->_warn("Couldn't find record length");
  }
  $reclen = substr($usmarc, 0, 5);
  if (preg_match("/^\\d{5}\$/", $reclen) || $reclen != strlen($usmarc)) {
    $this
      ->_warn("Invalid record length \"{$reclen}\"");
  }
  return $usmarc;
}