PHP:获取HTML标记内容和INSERT到表

时间:2014-06-05 04:01:06

标签: php html mysql

我有以下列表,其中包含<中的评论span> 标签< / span>

如何将每条评论保存到我的表格中?

<ul id="list">
  <li>
       <span>Comment 1</span>
  </li>
  <li>
       <span>Comment 2</span>
  </li>
  <li>
       <span>Comment 3</span>
  </li>
</ul>

我想把它保存到我的桌子上:

+----+--------+------------+
| id |  time  |   comment  |
+----+--------+------------+
| 1  |  12:05 |  Comment 1 |
+----+--------+------------+
| 2  |  14:20 |  Comment 2 |
+----+--------+------------+
| 3  |  17:41 |  Comment 3 |
+----+--------+------------+

我目前的PHP代码:

<?php
  $connect = mysqli_connect("localhost","daniel","password","comments_db");

  $time = time();

  // $comments = ??????;

  foreach($comments as $comment) {
      mysqli_query($connect,"INSERT INTO comments VALUES ('".$time."', '".$comment."')");
  }
?>

我怎样才能做到这一点?提前谢谢。

1 个答案:

答案 0 :(得分:0)

您每次只需收到一条评论,用户会将评论提交给您的服务器,您将保存该评论。