csvxml/index4.php

83 lines
2.4 KiB
PHP

<?PHP
declare(strict_types = 1);
error_reporting(E_ALL);
ini_set('display_errors', "1");
require_once __DIR__ . "/functions/functions.php";
if (session_status() != PHP_SESSION_ACTIVE) {
session_start();
}
// This array contains all available languages
$allowed_langs = ['ar', 'de', 'en', 'hu', 'id', 'it', 'pl','pt'];
// Some languages are in translation. They will only be available for logged in users.
if (isset($_GET['navlang'])) {
$_SESSION['lang'] = $_GET['navlang'];
if (!in_array($_SESSION['lang'], $allowed_langs)) $_SESSION['lang'] = 'de';
}
else if (!isset($_SESSION['lang'])) {
$_SESSION['lang'] = lang_getfrombrowser($allowed_langs, 'en', "", false);
}
$lang = $_SESSION['lang'];
require __DIR__ . "/translation-importer/$lang/csvxml-overview.php";
require 'inc/zeichen.php';
$filename = $_GET['fnam'];
$csv_datei = 'csv/' . $filename;
if (is_dir(__DIR__ . "/xml")) rrmdir(__DIR__ . '/xml');
mkdir("xml", 0755);
$fp = fopen ($csv_datei, 'r');
$y = 0;
while ($zeile = fgetcsv($fp, 100000, ';')) {
$y++;
$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 = $somecontent . '<record>' . "\n";
for ($x = 0; $x < count ( $zeile ); $x++)
{
$inhalt[$y][$x] = $zeile[$x];
$inhalt[$y][$x] = preg_replace('/[\x00-\x1F\x7F]/u', '', $inhalt[$y][$x]);
$inhalt[$y][$x] = str_replace('>', ']', str_replace('<', '[', $inhalt[$y][$x]));
if (empty($inhalt[$y][$x])) continue;
//if ($y!=1) $inhalt[$y][$x] = '<![CDATA['.$inhalt[$y][$x].']]>';
$somecontent = $somecontent . '<' . tagify(transform($inhalt[1][$x])) . '>' . (($inhalt[$y][$x])) . '</' . tagify(transform($inhalt[1][$x])) . '>' . "\n"; //für ungarn sonst weg }
}
$somecontent = $somecontent . '</record>';
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";exit;
}
fclose($handle);
}
fclose($fp);
echo printHTMLHead();
echo '
<div>
Please wait ... (transforming)
<hr />
' . ($y - 1) . ' files created
<br/>
<a href="zipit.php"><img src="img/go.gif"> Download as zip</a>
</div>';
echo '
</body>
</html>
';