Andreas: Zeilenweise löschen

Beitrag lesen

Hallo!!!

Ich bin gerade dabei zu versuchen einen kleinen Chat als Übung zu
konstruieren.
Den folgenden Code als chat.php abspeichern, beim starten müsste eine Fehlermeldung kommen diese "erstmal" ignorieren.
Dann "Options" auswählen und einen Nicknamen eingeben dies bestätigen
und man kann chatten. (hoffe das Layout stimmt überall, konnte es noch nicht auf mehreren Browsern testen!)
Es funktioniert noch nicht alles so wie ich mir es vorstelle,
bin ja auch Anfänger deswegen weis ich z.B. nicht wie man die Zeilen im Textfeld oben einzeln löscht wenn unten eine neue Zeile reingeschrieben wird.

Vielleicht kann mir ja einer dafür einen Tip geben.

PS. Das Prinzip der Funktionsweise würde ich gerne beibehalten.

<?php
//Author: - Andreas R. - 2004;

function inputtransform()
{
    if (isset($_REQUEST['input']) && !empty($_REQUEST['input'])) {
        $textfile = fopen("text.txt", "a+");
        fwrite($textfile, $_REQUEST['nick']. ":&nbsp;". $_REQUEST['input']. "\n");
        unset($_REQUEST['input']);
    }
    $text = file("text.txt");
    foreach ($text as $line => $_REQUEST['output']) {
        if ($line < 9) {
            echo $_REQUEST['output'];
            continue;
        }
        else {
            $textfile = fopen("text.txt", "w+");
            fwrite($textfile, $_REQUEST['output']);
            echo $_REQUEST['output'];
            break;
        }
    }
}
?>
<html>
<head>
<title>My Chat</title>
</head>
<body onLoad="document.chat.input.focus()" onContextMenu="return false">
<h1 style="font-family:arial; font-size:18pt;">My Chat</h1>
<form action="chat.php" method="post" name="chat">
<?php
if (isset($_REQUEST['options'])) {
?>
<hr style="width:45%; text-align:left; border:1px solid #C0C0C0;">
<?php
}
else {
?>
<hr style="width:45%; text-align:left; border:1px solid #000000;">
<?php
}
?>
<table border="0" width="45%" cellpadding="0" cellspacing="0">
  <tr>
    <td colspan="3">
      <div>&nbsp;</div>
    </td>
  </tr>
  <tr>
    <td colspan="2">
      <div style="font-family:arial; font-size:10pt; font-weight:bold;">Output:</div>
    </td>
    <td>
      <div style="font-family:arial; font-size:10pt; font-weight:bold;">User:</div>
    </td>
  </tr>
  <tr>
    <td colspan="3">
      <textarea rows="10" name="output" style="width:80%; margin-right:3px; overflow-y:hidden;" readonly>
<?php inputtransform(); ?>
      </textarea>
      <textarea rows="10" name="nicks" style="width:19%; overflow-y:hidden;" readonly>
<?php echo $_REQUEST['nick']; ?>
      </textarea>
    </td>
  </tr>
  <tr>
    <td colspan="3">
      <div>&nbsp;</div>
    </td>
  </tr>
  <tr>
    <td colspan="3">
      <div style="font-family:arial; font-size:10pt; font-weight:bold;">Input:</div>
    </td>
  </tr>
  <tr>
    <td width="45%">
      <input type="text" maxlength="33" name="input" size="35">
    </td>
    <td width="32%" align="left">
      <input type="submit" value="Send"><input type="reset" value="Delete">
    </td>
    <td align="right">
<?php
if (!isset($_REQUEST['options'])) {
?>
      <input type="submit" name="options" value="Options" style="width:65px;">
<?php
}
else {
?>
      <input type="submit" name="ok" value="OK" style="width:65px;">
<?php
}
?>
    </td>
  </tr>
</table>
<br>
<?php
if (isset($_REQUEST['options'])) {
?>
<hr style="width:45%; text-align:left; border:1px solid #000000;">
<div style="font-family:arial; font-size:10pt; font-weight:bold; margin-bottom:2px;">Options:</div>
</table>
<table width="100" cellpadding="0" cellspacing="5" style="border:2px dashed #C0C0C0;">
  <tr>
    <td style="width:50px;">
      <div style="font-family:arial; font-size:8pt; font-weight:bold;">Name:</div>
    </td>
    <td>
      <input type="text" maxlength="8" size="6" name="nick" value="<?php echo $_REQUEST['nick']; ?>" style="font-family:arial; font-size:8pt;">
    </td>
  </tr>
  <tr>
    <td>
      <div style="font-family:arial; font-size:8pt; font-weight:bold;">Chats:</div>
    </td>
    <td>
      <select name="chats" style="font-family:arial; font-size:8pt;">
      <option>Chat-1</option>
      <option>Chat-2</option>
      <option>Chat-3</option>
      </select>
    </td>
  </tr>
  <tr>
    <td>
      <div style="font-family:arial; font-size:8pt; font-weight:bold;">Infos:</div>
    </td>
    <td>
      <input type="checkbox" name="infos" checked>
    </td>
  </tr>
</table>
<br>
<hr style="width:45%; text-align:left; border:1px solid #C0C0C0;">
<?php
}
else {
?>
  <tr>
    <td colspan="3">
      <hr style="width:45%; text-align:left; border:1px solid #C0C0C0;">
    </td>
  </tr>
</table>
<input type="hidden" name="nick" value="<?php echo $_REQUEST['nick']; ?>">
<?php
}
?>
</form>
</body>
</html>