1 | <?php |
---|
2 | // +-------------------------------------------------+ |
---|
3 | // © 2002-2004 PMB Services / www.sigb.net pmb@sigb.net et contributeurs (voir www.sigb.net) |
---|
4 | // +-------------------------------------------------+ |
---|
5 | // $Id: input_xml.inc.php,v 1.11 2015-04-03 11:16:25 jpermanne Exp $ |
---|
6 | |
---|
7 | if (stristr($_SERVER['REQUEST_URI'], ".inc.php")) die("no access"); |
---|
8 | |
---|
9 | function _get_n_notices_($fi,$file_in,$input_params,$origine) { |
---|
10 | //pmb_mysql_query("delete from import_marc"); |
---|
11 | $index=array(); |
---|
12 | $i=false; |
---|
13 | $encoding=""; |
---|
14 | $n=1; |
---|
15 | $fcontents=""; |
---|
16 | while ($i===false) { |
---|
17 | $i=strpos($fcontents,"<".$input_params['NOTICEELEMENT'].">"); |
---|
18 | if ($i===false) $i=strpos($fcontents,"<".$input_params['NOTICEELEMENT']." "); |
---|
19 | if ($i!==false) { |
---|
20 | //on pense à récup le charset du xml |
---|
21 | if($encoding === ""){ |
---|
22 | $s=strpos($fcontents,"<?xml"); |
---|
23 | $e=strpos($fcontents,"?>"); |
---|
24 | if(isset($s) && isset($e)){ |
---|
25 | $entete = substr($fcontents,$s,$e+2); |
---|
26 | $rx = "/<?xml.*encoding=[\'\"](.*?)[\'\"].*?>/m"; |
---|
27 | if (preg_match($rx,$entete, $m)) $encoding = strtoupper($m[1]); |
---|
28 | } |
---|
29 | } |
---|
30 | $i1=strpos($fcontents,"</".$input_params['NOTICEELEMENT'].">"); |
---|
31 | while ((!feof($fi))&&($i1===false)) { |
---|
32 | $fcontents.=fread($fi,4096); |
---|
33 | $i1=strpos($fcontents,"</".$input_params['NOTICEELEMENT'].">"); |
---|
34 | } |
---|
35 | if ($i1!==false) { |
---|
36 | $notice=substr($fcontents,$i,$i1+strlen("</".$input_params['NOTICEELEMENT'].">")-$i); |
---|
37 | $requete="insert into import_marc (no_notice, notice, origine, encoding) values($n,'".addslashes($notice)."','$origine','$encoding')"; |
---|
38 | pmb_mysql_query($requete); |
---|
39 | $n++; |
---|
40 | $index[]=$n; |
---|
41 | $fcontents=substr($fcontents,$i1+strlen("</".$input_params['NOTICEELEMENT'].">")); |
---|
42 | $i=false; |
---|
43 | } |
---|
44 | } else { |
---|
45 | if (!feof($fi)) |
---|
46 | $fcontents.=fread($fi,4096); |
---|
47 | else break; |
---|
48 | } |
---|
49 | } |
---|
50 | |
---|
51 | return $index; |
---|
52 | } |
---|
53 | |
---|
54 | ?> |
---|