我一直在做一个简单的聊天功能。我的代码有两个问题:
- 我希望新帖子出现在文本文件的顶部。
- 我希望输入按钮将一些 html 代码写入文本区域,以便更轻松地格式化使用的文本。
这是代码:
<script type="text/javascript">
forma1 = "<B> </B>"
forma2 = "<font color="#B2E0B2"> </font>"
forma3 = "<font color="#C2E0FF"> </font>"
forma4 = "<font color="#FFC2C2"> </font>"
</script>
<form method="post">
<div align="center">
<input name="navn" type="text" size="30" style="color:#68748D;" value="Navn" onfocus="if (this.value == 'Navn') this.value = '';"/>
<input type="button" onkeypress="form1('area');"/>
<input type="button" onkeypress="form2('area');"/>
<input type="button" onkeypress="form3('area');"/>
<input type="button" onkeypress="form4('area');"/>
<br>
<textarea name="txt" cols="55" rows="5" id="area"></textarea>
<br><br> <input type="submit" value="Send" name="submit" class="a" />
</div>
<?php
if ( isset( $_POST[ 'submit' ] ) ) {
$dude = $_POST ['navn'];
$time = gmdate("M d Y H:i:s",time()+(2*60*60));
$com = $_POST['txt'];
$fp = $file = fopen( "msgs.txt", "a");
fwrite($file, $time);
fwrite($file, "<br>");
fwrite($file, '<font color="#68748D" style="font-weight:800;" size="+2">');
fwrite($file, $dude);
fwrite($file, '</font>');
fwrite($file, "<br>");
fwrite($file, $com);
fwrite($file, "<br>________________________________________________________________________<br>" );
fclose($fp);
echo '<script type="text/javascript">window.location ="";</script>';
}
?>
<br>
</form>
<font><b><p>Output: </p></b></font>
<fontcolor="#000" size="2">
<?php
if (file_exists("msgs.txt")) {
$file = fopen( "msgs.txt", "r" );
echo fread( $file, filesize( "msgs.txt" ) );
fclose( $file );
}
?>
</font>
谢谢你。