function handle_mnem($f) { $p = new MarcMnemParser(); 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); }
$p = new MarcParser(); // on crée la variable $xml $xml = ""; $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");
$f = @fopen($notice_unimarc, 'rb'); // on crée l'analyseur de fichier unimarc (basé sur la librairie MARC.php) $p = new MarcParser(); // on crée la variable $xml $xml = ""; $xml .= "<livre>\n"; // 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); $p->records = array(); } $p->eof(); // on ferme la balise xml $xml .= "</livre>\n"; // on nettoie les esperluettes &, en les remplaçant par & // (pour éviter d'avoir une erreur indesign à l'importation) $xml = str_replace('&', '&', $xml); // on enregistre le contenu de la variable $xml dans le fichier lelivre.xml file_put_contents("lelivre.xml", $xml); // on affiche dans la console le fait que le script est terminé echo "\n!!!! fin\n"; /** * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */