csvxml/csv_laden_hu_alt.php

50 lines
1.9 KiB
PHP
Raw Normal View History

2019-08-25 21:45:52 +02:00
<?php
ob_start();
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />'; // f<>r ungarn sonst weg //////////////////////
include ('inc/zeichen.php');
$filename=$_GET['fnam'];
$csv_datei = 'csv/'.$filename;
mkdir("xml",0777);
$fp = fopen ( $csv_datei, 'r' );
$y = 0;
while ( $zeile = fgetcsv ( $fp, 100000, ';' ) )
//while ( $zeile = fgetcsv ( $fp, 100000, ',' ) )
{
$y++;
//echo '<b>Zeile='.$y.' Anzahl in Zeile: '.count ( $zeile ).'</b><br>';
$zieldatei = 'xml/'.$y.'.xml';
if (!$handle = fopen($zieldatei, 'w'))
{
echo "Cannot open file ($zieldatei)";exit;
}
$somecontent='<?xml version="1.0" encoding="UTF-8"?>'."\n"; // f<>r Ungarn ///////////////////////////////////
/*$somecontent='<?xml version="1.0" encoding="ISO-8859-1"?>'."\n"; // normal */
$somecontent=$somecontent.'<record>'."\n";
for ( $x = 0; $x < count ( $zeile ); $x++ )
{
$inhalt[$y][$x]=$zeile[$x];
//echo '<b>'.$inhalt[1][$x].'</b> --> '.$zeile[$x].'<br>';
if ($inhalt[$y][$x]=='') $inhalt[$y][$x]='ERSATZ';
//$somecontent=$somecontent.'<'.tagify(transform($inhalt[1][$x])).'>'.utf8_decode(transform($inhalt[$y][$x])).'</'.tagify(transform($inhalt[1][$x])).'>'."\n"; // f<>r utf8
$somecontent=$somecontent.'<'.tagify(transform($inhalt[1][$x])).'>'.(($inhalt[$y][$x])).'</'.tagify(transform($inhalt[1][$x])).'>'."\n"; //f<>r ungarn sonst weg //////////////////////////////////////////////////////////////
//$somecontent=$somecontent.'<'.tagify(transform($inhalt[1][$x])).'>'.transform($inhalt[$y][$x]).'</'.tagify(transform($inhalt[1][$x])).'>'."\n"; //normaleinstellung
}
echo $y.'<br>';
$somecontent=$somecontent.'</record>';
//if ($y>1)
//{
if (fwrite($handle, $somecontent) === FALSE)
{
echo "Cannot write to file ($filename)";exit;
}
// echo "Success, wrote to file ($filename)<br><br>";
//}
fclose($handle);
}
fclose($fp);
echo '<a href="zipit.php">download as zip</a>';
?>