function handle_marc($f) { $p = new MarcParser(); while ($buf = fread($f, 8192)) { $err = $p->parse($buf); if (is_a($err, 'MarcParseError')) { die("Bad MARC record, giving up: " . $err->toStr()); } print_recs($p->records); $p->records = array(); } $p->eof(); print_recs($p->records); }
$xml .= "<livre>\n"; $notices = array(); // on parcours le fichier de notices while ($buf = fread($f, 8192)) { $err = $p->parse($buf); // on vérifie qu'il n'y a pas d'erreur dans le fichier unimarc if (is_a($err, 'MarcParseError')) { die("Bad MARC record, giving up: " . $err->toStr()); } // on stocke dans le xml le résultat de la fonction print_recs() // elle est appelée pour chaque notice trouvée //$xml .= print_recs( $p->records ); $notices = array_merge($notices, print_recs($p->records)); $p->records = array(); } $p->eof(); // print_r($notices); // ksort($notices); // echo ("TRI TRI +++++++++++++++\n"); // print_r($notices); function cmp($a, $b) { if ($a->index == $b->index) { return 0; } return $a->index < $b->index ? -1 : 1; } usort($notices, "cmp"); $i = 0; foreach ($notices as $key => $xml_notice) { echo $i . " " . $xml_notice->index . "\n";