From 0ba9a3b1ec6599952e9b2536c55539e8c54e80be Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Tue, 15 Mar 2022 10:29:19 +0100 Subject: [PATCH] Fix type error --- public/csv.php | 2 +- public/index.php | 2 +- public/index6.php | 20 +++++++++++++------- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/public/csv.php b/public/csv.php index cbfe60c..367a95d 100644 --- a/public/csv.php +++ b/public/csv.php @@ -12,7 +12,7 @@ if (session_status() != PHP_SESSION_ACTIVE) { } // This array contains all available languages -$allowed_langs = ['ar', 'de', 'en', 'hu', 'id', 'it', 'pl','pt']; +$allowed_langs = ['ar', 'de', 'en', 'hu', 'id', 'it', 'pl', 'pt']; // Some languages are in translation. They will only be available for logged in users. diff --git a/public/index.php b/public/index.php index 6bc2d6c..0548ea2 100644 --- a/public/index.php +++ b/public/index.php @@ -14,7 +14,7 @@ if (session_status() != PHP_SESSION_ACTIVE) { } // This array contains all available languages -$allowed_langs = ['ar', 'de', 'en', 'hu', 'id', 'it', 'pl','pt']; +$allowed_langs = ['ar', 'de', 'en', 'hu', 'id', 'it', 'pl', 'pt']; // Some languages are in translation. They will only be available for logged in users. diff --git a/public/index6.php b/public/index6.php index 1803ff6..fd0b8af 100644 --- a/public/index6.php +++ b/public/index6.php @@ -7,7 +7,7 @@ if (session_status() != PHP_SESSION_ACTIVE) { } // This array contains all available languages -$allowed_langs = ['ar', 'de', 'en', 'hu', 'id', 'it', 'pl','pt']; +$allowed_langs = ['ar', 'de', 'en', 'hu', 'id', 'it', 'pl', 'pt']; // Some languages are in translation. They will only be available for logged in users. @@ -33,7 +33,7 @@ if (!($fp = fopen($csv_datei, 'r'))) { throw new MDmainEntityNotExistentException("Failed opening file"); } $y = 0; -while ($zeile = fgetcsv($fp, 100000, ';')) { +while ($zeile = fgetcsv($fp, 100000, ';', "\"")) { $zeile = str_replace("\xEF\xBB\xBF", '', $zeile); @@ -41,7 +41,8 @@ while ($zeile = fgetcsv($fp, 100000, ';')) { $zieldatei = __DIR__ . '/../xml/' . $y . '.xml'; if (!$handle = fopen($zieldatei, 'w')) { - echo "Cannot open file ($zieldatei)";exit; + echo "Cannot open file ($zieldatei)"; + exit; } $xmlDoc = new DOMDocument("1.0", "UTF-8"); @@ -52,13 +53,17 @@ while ($zeile = fgetcsv($fp, 100000, ';')) { $record_node = $xmlDoc->appendChild($xmlMainElem); //add record element to XML node # $rss_node->setAttribute("version", "2.0"); //set RSS version - $lineCount = count($zeile); + if (empty($lineCount)) $lineCount = count($zeile); for ($x = 0; $x < $lineCount; $x++) { $inhalt[$y][$x] = $zeile[$x]; if ($inhalt[$y][$x] == '') $inhalt[$y][$x] = 'ERSATZ'; - $record_node->appendChild(createTextDomElement($xmlDoc, trim($inhalt[1][$x]), trim($inhalt[$y][$x]))); + if (!isset($inhalt[1][$x])) { + echo "Error at position $x"; + } + + $record_node->appendChild(createTextDomElement($xmlDoc, trim($inhalt[1][$x] ?? ""), trim($inhalt[$y][$x] ?? ""))); } @@ -67,8 +72,9 @@ while ($zeile = fgetcsv($fp, 100000, ';')) { # $somecontent .= ''; //if ($y>1) //{ - if (fwrite($handle, $somecontent) === FALSE) { - echo "Cannot write to file ($filename)";exit; + if (fwrite($handle, $somecontent) === false) { + echo "Cannot write to file ($filename)"; + exit; } fclose($handle);