简体   繁体   中英

How can I properly show html tags which is come from mysql database using php?

Well, In Mysql Database where a table column contain following text :

Column Text :

<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>

I want to show it properly to to the browser. So that I am using following php code:

$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;
}

But it's showing following text format instead of bold, color, list item etc :

<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> 

The text is insert to db using this method :

function validate($str){
    global $connect;
    $str =  trim($str);
    $str =  stripslashes($str);
    $str =  htmlspecialchars($str);
    $str =  mysqli_real_escape_string($connect, $str);
    return $str;
}

use htmlspecialchars_decode() or html_entity_decode() function

echo htmlspecialchars_decode($blog_description);

or

  echo html_entity_decode($blog_description);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM