我用php创建了一个聊天室,我希望能够添加评论帖子的能力,为此,我需要能够在php中的短语后找到一个数字。
该短语将始终为“这是帖子号码:”但该号码会根据您正在查看的帖子的帖子编号而变化。
下面,我有将格式化用户输入插入.txt文件的代码:
//increases the post number by 1
$post_num = file_get_contents("post_num.txt");
$post_num ++;
file_put_contents("post_num.txt", $post_num);
//writes message to file
file_put_contents('posts.txt', "<div class='post'><div class='title'><b>" . $title . "</b></div>" . $postimg . "<div class='message'>" . showBBcodes($message) . "</div><div class='footer'>Posted By: " . $username . "<br> This is post number: " . $post_num . "</div><form action='finish_comment.php' method='post'><input placeholder='comment' name='comment'><input type='submit' value='comment'></form></div><br> \n", FILE_APPEND);
//redirects the user back to posts.php
echo "<script>location.href = 'posts.php'</script>";
带有帖子编号的短语位于以下代码中:
<div class='footer'>Posted By: " . $username . "<br> This is post number: " . $post_num . "</div>