Hallo,
ich habe hier ein seltsames Problem, es wird 2x der true Zweig angesteuert, hier der Quote:
Es handelt sich um eine Art Editor für .pgn Dateien (Schachpartien), ich möchte einfach wenn die $lines empty ist oder halt der Windows "\r" einmal das hidden Feld emptyline ausgeben, bei meinen Versuchen wird es aber doppelt ausgegeben oder gar nicht. Versteht das einer? Wieso? Welhalb? Stackoverflow würde ich gerne Fragen, aber die haben mich gesperrt.
mfg
ich habe hier ein seltsames Problem, es wird 2x der true Zweig angesteuert, hier der Quote:
Code:
public function readpgnforedits($file) {
$f = file_get_contents($file);
$lines = explode("\n", $f);
$nextgame = 0;
$moves = array();
$movesnum = 0;
echo('<h2>Änderung an ' . $file . '</h2>' . "\n");
echo('<FORM action="writepgn.php" method="POST" class="readpgn">' . "\n");
for ($x = 0; $x <= count($lines); $x++) {
$xi = $x + 1;
// seperate by spaces
$comp = explode(" ", $lines[$x]);
//if line begins with [
if (substr($lines[$x], 0, 1) == "[") {
if (count($comp) > 2) {
$first = substr($comp[0], 1);
$lastpart = array_slice($comp, 1);
$last = implode(" ", $lastpart);
$last = substr($last, 0, -3);
$last = substr($last, 1);
} else {
$first = substr($comp[0], 1);
$last = substr($comp[1], 0, -3);
$last = substr($last, 1);
}
echo('<label for="' . $first . $nextgame . '">' . $first . ' </label>' . "\n");
echo('<INPUT type="text" VALUE="' . $last . '" name="' . $first . $nextgame . '"><br><br>' . "\n");
} else {
// if line doesn't begin with [ it must be a moves line or empty line
/////////
// HIER IST DAS PROBLEM!!!!
////////////
if (($lines[$x] == "\r") || ($lines[$x] == "")) {
echo('<input type="hidden" name="emptyline">'."\n");
} else {
array_push($moves, $lines[$x]);
}
// check next line for header line?
if (substr($lines[$xi], 0, 1) == "[") {
echo('<label for="thisismovesline' . $nextgame . '">Moves <div class="small">Änderungen hier sind nicht empfohlen</div></label>' . "\n");
echo("\n<textarea name=\"thisismovesline" . $nextgame . "\" rows=\"20\" cols=\"90\">");
$moves = implode("\n", $moves);
echo $moves;
echo('</textarea><br>' . "\n");
$nextgame++;
unset($moves);
$moves = array();
echo("<hr>\n");
}
// this adds last textarea, sadly condition above is wrong or something..
if (($xi > count($lines))) {
echo('<label for="thisismovesline".$nextgame.">Moves <div class="small">Änderungen hier sind nicht empfohlen</div></label>' . "\n");
echo("\n<textarea name=\"thisismovesline" . $nextgame . "\" rows=\"20\" cols=\"90\">");
$moves = implode("\n", $moves);
echo $moves;
echo('</textarea><br>' . "\n");
$nextgame++;
unset($moves);
$moves = array();
echo("<hr>\n");
}
}
}
echo $nextgame . " Games in this .pgn file.<br>\n";
echo("\n" . '<br><input type="hidden" id="file" name="filename" value="' . $file . '">');
echo("<br>\n");
echo("\n" . '<label for="pw">Passwort </label>');
echo("\n" . '<input type="password" name="pw" id="pw" maxlength="64">');
echo("\n" . '<br><br><input type="submit" id="ok" value=" Ändern ">');
echo("\n" . '<input type="reset" id="reset" value=" Reset ">');
echo("\n" . '</FORM>');
}
mfg