我创建了一个cms,并在我的博客文章中编写以下代码来显示代码。
<pre>
<code>
<input type="color" name="favcolor" />
</code>
</pre>
它显示了
<input type="color" name="favcolor" />
在我的博客上。然而,回到我的编辑页面,一旦保存并刷新,代码就会变成这样:
<pre>
<code>
<input type="color" name="favcolor" />
</code>
</pre>
如何在编写时显示代码?据我所见,代码保存在mysql数据库中。所以我猜我拿东西的时候做错了什么。。
下面是我用来在编辑页面上显示内容的函数。
function get_post($post_id){
include('includes/database.php');
$sql = 'SELECT post_id, post_content FROM blog_posts WHERE post_id = ?';
try {
$post_stmt = $pdo->prepare($sql);
$post_stmt->bindValue(1,$post_id,PDO::PARAM_INT);
$post_stmt->execute();
return $post_stmt->fetch();
} catch (Exception $e) {
echo 'Error:'.$e->getMessage().'</ br>';
return array();
}
}
在edit-post.php上
$row = get_post($post_id);
<textarea name='post_content' id="post_content">
<?php echo $row['post_content'];?>
</textarea>
总而言之,问题是:转义的html在保存到编辑页上时变得不可转义。问题:如何在编辑页上保留转义的html?
1条答案
按热度按时间qlckcl4x1#
就像这样。。。