0

I just want to find an HTML part. There are two tables in there and they both begin with a text saying "Vertretungsplan". So there is a part in my function to find out in which part the HTML-String exists. But this function does not what it should do. There is a wrong number given from the first two preg_match_all! But the strpos and strripos don´t work, too. This is the code:

<?php
function faellt($kursnr, $stunde) {
    $zahl = 0;
    if ($stunde == "2") {
        $stunde = "3";
    }
    elseif ($stunde == "3") {
        $stunde = "5";
    }
    elseif ($stunde == "4") {
        $stunde = "7";
    }
    elseif ($stunde == "5") {
        $stunde = "9";
    }
    $file = file_get_contents("vertretungsplan.html");
    $quellcode = preg_replace("/.*<body[^>]*>|<\/body>.*/si", "", $file);
    preg_match_all('%<tr><td class="KlasseNeu">Q1<br></td><td class="StundeNeu">'.$stunde.'<br></td><td class="FachNeu">'.$kursnr.'<br></td><td class="RaumNeu"><br></td><td class="AnmerkungNeu">fällt aus<br></td></tr>%s', $quellcode, $treffer);
    preg_match_all('%<tr><td class="KlasseNeu">Q2<br></td><td class="StundeNeu">'.$stunde.'<br></td><td class="FachNeu">'.$kursnr.'<br></td><td class="RaumNeu"><br></td><td class="AnmerkungNeu">fällt aus<br></td></tr>%s', $quellcode, $treffer2);
    $zahl = count($treffer) + count($treffer2);
    //$zahl = $zahl - 2;

    if ($zahl != 0) {
        /*preg_match_all("/Vertretungsplan/",$quellcode,$ausgabe, PREG_OFFSET_CAPTURE);
        $erster = $ausgabe[0];
        $zweiter = $ausgabe[1];*/

        $erster = strpos($quellcode, "/Vertretungsplan/");
        $zweiter = strripos($quellcode, "/Vertretungsplan/");

        if ($erster != $zweiter) {
            $erst = strpos($quellcode, $kursnr);
            if ($erst > $erster AND $erst < $zweiter) {
                $faellt = "eins";
            }
            elseif (§erst > $zweiter) {
                $faellt = "zwei";
            }
        }
        elseif ($erster == $zweiter) {
            $faellt = "eins".$quellcode;
        }
    }
    else {
        $faellt = "false";
    }
    return $faellt;
}
?>
marcoR
  • 1
  • 1
  • 2

0 Answers0