php - 带时间输入的 PHP 注释部分
问题描述
我想用大部头条目制作一个评论框。例如
John S. :这是一条评论。
发送时间:下午 3:24
所以这是我的代码。有人可以帮我弄这个吗?
<form method="post">
<textarea name="txt" cols="25" rows="5" placeholder="Type here your comment!" required="required"></textarea>
<br><input type="submit" value="Submit" name="submit" />
<?php
if ( isset( $_POST[ 'submit' ] ) ) {
$com = $_POST[ "txt" ];
$file = fopen( "inrg.txt", "a" );
fwrite( $file, "<br> <font color=\"#44b9df\"><em>User:</em></font> " );
for ( $i = 0; $i <= strlen( $com ) - 1; $i++ ) {
fwrite( $file, $com[ $i ] );
if ( $i % 37 == 0 && $i != 0 ) fwrite( $file, "<br/>" );
}
fwrite( $file, "<br><hr>" );
fclose( $file );
}
?>
<br>
</form>
</div>
<div class="commentcard"><a name="comments">
<font face="Times New Roman"><b><p class="commentcimsor">Comments: </p></b></font>
<font face="Comic Sans MS" color="#000" size="4"><div class="commentscroll">
<?php
if (file_exists("inrg.txt")) {
$file = fopen( "inrg.txt", "r" );
echo fread( $file, filesize( "inrg.txt" ) );
fclose( $file );
}
?>
解决方案
添加这一行:
fwrite($file, "Sent: ".date('h:iA')."<br>");
在评论之后,所以fwrite( $file, "<br><hr>" );
在行之前。
这个输出是这样的:
Sent: 09:23PM<br>
如果您需要不同的格式,请查看日期文档https://www.php.net/manual/en/function.date.php - 它的格式参数。
推荐阅读
- sql - 如何在 WHERE LIKE 中对多个值使用 SELECT 语句
- android-studio - 无法开始在archlinux上使用ndk android studio
- php - Laravel eloquent 表关系排序数据
- google-cloud-platform - Google AutoML 训练错误
- android - 输入路径中的Android ffmpeg空白导致“没有这样的文件或目录”
- php - MVC没有打开链接它应该如何“控制器/动作”
- dataframe - 使用 pyspark 为动态表创建 XPATH 行
- javascript - withRouter 不会将 Route 道具传递给组件
- c# - 仅显示标题数据但不显示数据集上的详细信息数据(水晶报表 c#)
- reactjs - React-Bootstrap 在检查用户电子邮件是否经过验证时,我无法显示警报