[英]How can I properly show html tags which is come from mysql database using php?
好吧,在Mysql數據庫中,其中一個表列包含以下文本:
欄文字:
<ol>
<li><a href="http://web-kreation.com/">Web-Kreation</a> for helping out with graphics on the site</li>
<li></li>
<li><a href="http://www.famfamfam.com/lab/icons/silk/">famfamfam.com</a> (Mark James) Silk Icon's used by NicEdit theme</li>
<li></li>
<li>Matthias Miller, Dean Edwards and John Resig work on onDOMReady function used in the library</li>
<li></li>
<li><span style="color: #808000; background-color: #ffff00;"><a style="color: #808000; background-color: #ffff00;" href="http://www.prototypejs.org/">Prototype</a> (Sam Stephenson) for inspriation for several library functions</span></li>
</ol>
<p><strong>tinyMCE, FCKEditor<a class="example1" title="My ayhoo main" href="http://www.yahoo.com" target="_blank">Yahoo</a> both great editors used for ideas</strong></p>
<p><strong><img src="../libs/tinymce/js/tinymce/plugins/emoticons/img/smiley-innocent.gif" alt="innocent" /></strong></p>
<p>&nbsp;</p>
我想將其正確顯示給瀏覽器。 這樣我就使用以下php代碼:
$author = $_SESSION['username'];
$query = mysqli_query($connect, "SELECT * FROM blog WHERE author = '$author' ");
while($row = mysqli_fetch_array($query)){
$blog_description = $row['blog_description'];
$blog_description = nl2br($blog_description);
echo $blog_description;
}
但是它顯示以下文本格式,而不是粗體,顏色,列表項等:
<ol>
<li><a href="http://web-kreation.com/">Web-Kreation</a> for helping out with graphics on the site</li>
<li></li>
<li><a href="http://www.famfamfam.com/lab/icons/silk/">famfamfam.com</a> (Mark James) Silk Icon's used by NicEdit theme</li>
<li></li>
<li>Matthias Miller, Dean Edwards and John Resig work on onDOMReady function used in the library</li>
<li></li>
<li><span style="color: #808000; background-color: #ffff00;"><a style="color: #808000; background-color: #ffff00;" href="http://www.prototypejs.org/">Prototype</a> (Sam Stephenson) for inspriation for several library functions</span></li>
</ol>
<p><strong>tinyMCE, FCKEditor<a class="example1" title="My ayhoo main" href="http://www.yahoo.com" target="_blank">Yahoo</a> both great editors used for ideas</strong></p>
<p><strong><img src="../libs/tinymce/js/tinymce/plugins/emoticons/img/smiley-innocent.gif" alt="innocent" /></strong></p>
<p> </p>
使用以下方法將文本插入db:
function validate($str){
global $connect;
$str = trim($str);
$str = stripslashes($str);
$str = htmlspecialchars($str);
$str = mysqli_real_escape_string($connect, $str);
return $str;
}
使用htmlspecialchars_decode()或html_entity_decode()函數
echo htmlspecialchars_decode($blog_description);
要么
echo html_entity_decode($blog_description);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.