Liebe Typo3 Freunde 🙂,
ich habe ein PHP Script geschrieben, welches ein XML File eines Parkhauses parst und ausgibt, wieviele Parkplätze frei bzw. besetzt sind:
<?php
$bool_1 = false;
$bool_2 = false;
$bool_3 = false;
$bool_4 = false;
$timestamp = false;
$int_Belegung;
$int_Frei;
// run when start tag is found
function startElementHandler($parser, $name, $attrubutes)
{
global $bool_1;
global $bool_2;
global $bool_3;
global $timestamp;
if($name == "PARKHAUS") {
$bool_1 = true;
}
if($bool_1 == true && $name == "BELEGUNG_KURZ") {
$bool_2 = true;
}
if($bool_1 == true && $name == "RESTPLAETZE_KURZ") {
$bool_3 = true;
}
if($name == "ZEITSTEMPEL") {
$timestamp = true;
}
}
// run when end tag is found
function endElementHandler($parser, $name)
{
global $bool_1;
global $bool_2;
global $bool_3;
global $bool_4;
global $timestamp;
if($name == "PARKHAUS") {
$bool_1 = false;
$bool_4 = false;
}
if($name == "BELEGUNG_KURZ") $bool_2 = false;
if($name == "RESTPLAETZE_KURZ") $bool_3 = false;
if($name == "ZEITSTEMPEL") $timestamp = false;
}
// run when cdata is found
function characterDataHandler($parser, $cdata)
{
global $bool_1;
global $bool_2;
global $bool_3;
global $bool_4;
global $timestamp;
global $int_Belegung;
global $int_Frei;
if(!strcmp("Bad. Bahnhof",$cdata)) {
$bool_4 = true;
}
if($bool_2 && $bool_4) {
$int_Belegung = $cdata;
}
if($bool_3 && $bool_4) {
$int_Frei = $cdata;
}
if($timestamp) {
}
}
// XML data file
$xml_file = "http://www.parkleitsystem-basel.ch/PPS_Basel.xml";
// initialize parser
$xml_parser = xml_parser_create();
// set callback functions
xml_set_element_handler($xml_parser, "startElementHandler", "endElementHandler");
xml_set_character_data_handler($xml_parser, "characterDataHandler");
// read XML File
if (!($fp = fopen($xml_file, "r")))
{
die("File I/O error_ $xml_file");
}
// parse XML
while ($data = fread($fp, 4096))
{
// error handler
if (!xml_parse($xml_parser, $data, feof($fp)))
{
die("XML parser error: " . xml_error_string(xml_get_error_code($xml_parser)));
}
}
// all done, cleain up!
xml_parser_free($xml_parser);
/ now we hand the result to typo3
$content = "
<tr class="\"statItemRow\"">
<td><span class="\"statItem\"" style="\"background-color:" 39be00="" color:="" ffffff="">$int_Frei FREI</span></td>
</tr>
<tr class="\"statSpacerRow\""></tr>
<tr class="\"statItemRow\"">
<td><span class="\"statItem\"" style="\"background-color:" bd0000="" color:="" ffffff="">$int_Belegung BESETZT</span></td>
</tr>
<tr class="\"statSpacerRow\""></tr>
<tr class="\"statItemRow\"">
<td><span class="\"statItem\"" style="\"background-color:" efdb00="" color:="" 000000="">AKTUALISIEREN</span></td>
</tr>
<tr class="\"statSpacerRow\""></tr>";
echo $content;
?>
Das Script habe ich im Setup mit folgenden Befehlen eingefĂĽgt:
temp.xmlparse = PHP_SCRIPT
temp.xmlparse.file = media/scripts/xmlparse2.php
Der Link zur Seite:
Das Script habe ich ausserdem auf folgender Adresse als eigenständiges PHP Script installiert, damit Ihr Euch versichern könnt, dass es an sich funktioniert (das einzige was ich geändert habe, ist die Ausgabe der Variable $content, also die Zeile "echo $content;" am Schluss eingefügt:
http://www.visign.ch/parkhaus/xmlparse2.php
Das Problem ist nun, dass die Anzahl freier/besetzter Parkplätze, also die Variablen "$int_Frei" und $int_Belegung" in der Endausgabe nicht mit in den String aufgenommen werden.
Die Gewünsche Ausgabe, zu Unterst im Quelltext der Webpage zu finden, wäre folgendes (wie sie im eigenständigen Script oben auch herauskommt):
<tr class="statItemRow">
<td><span class="statItem" style="background-color: #39BE00; color: #FFFFFF">112 FREI</span></td>
</tr>
<tr class="statSpacerRow"></tr>
<tr class="statItemRow">
<td><span class="statItem" style="background-color: #BD0000; color: #FFFFFF">188 BESETZT</span></td>
</tr>
<tr class="statSpacerRow"></tr>
<tr class="statItemRow">
<td><span class="statItem" style="background-color: #EFDB00; color: #000000">AKTUALISIEREN</span></td>
</tr>
<tr class="statSpacerRow"></tr>
aber die Zahlen fehlen dann eben, wenn Typo3 das Script in die Seite integriert.
Ich wäre wirklich dankbar, wenn jemand eine Idee hätte.
Viele GrĂĽsse,
Frankie