输入值中的HTML代码不会显示

时间:2014-08-14 17:16:09

标签: php html phpmyadmin

当我使用此代码时:

<textarea value="<?php echo $content['content']; ?>"></textarea>

$内容[&#39;内容&#39;]:

<table class="table table-striped">
<tr><th>Age</th><th>Name</th></tr>
<tr><td>13</td><td>Zach</td></tr>
<tr><td>13</td><td>Tyler</td></tr>
</table>
Yep.

从我的数据库中获取帖子内容,这就是<textarea>

中显示的内容
<tr><th>Age</th><th>Name</th></tr>
<tr><td>13</td><td>Zach</td></tr>
<tr><td>13</td><td>Tyler</td></tr>
</table>
Yep.">

我尝试在htmlspecialchars()周围使用$content['content'],但这不起作用。有任何想法吗? 注意:$ content只是从数据库中提取的关联数组。

2 个答案:

答案 0 :(得分:2)

Textarea不使用value属性。把它放在标签之间,如:

<textarea name="myhtmltextarea" rows="5" cols="40">
<?php echo htmlspecialchars($content['content']); ?>
</textarea>

有关支持的属性和用途的详情,请参阅此处:https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea

答案 1 :(得分:0)

<textarea><?php echo $content['content']; ?></textarea>