将表单字段中的输入保存到sql数据库varchar(255)...输入将类似于:
<a href="test.com">Author Name</a>
最重要的是,大多数时候它很可能会有html标签。当我从数据库中检索并输出时,我得到类似的东西:
<a href="test.com">Author Name</a>
因为这应该作为html回显它在页面上没有正确显示。也许我只是累了,但我无法弄清楚如何将其输出为非编码,以便浏览器正确读取。
答案 0 :(得分:0)
试试这个:
<?php
echo htmlspecialchars_decode("<a href="test.com">Author Name</a>");
?>
为什么在插入数据库之前编码html标签?
答案 1 :(得分:0)
#Connect to the DB
$db = mysql_connect('localhost', 'root', '');
#Select the DB name
mysql_select_db('test');
#html tag contain in a string='$str'
$str='<a href="test'.'.com"'.'>Author Name</a>';
###insert query section ###
#Ask for UTF-8 encoding
mysql_query("SET NAMES 'utf8'");
#Set the Query
$sql = "INSERT INTO `test`.`code` (`name`) VALUES ('$str');";//Save it in a text row, that's it...
#Run the query
mysql_query($sql);
###fetching result###
#fetching required info from mysql
$sqlQuery1 = "SELECT * FROM `code` WHERE `name` LIKE '$str'";
$result1 = mysql_query($sqlQuery1); //order executes
$row1 = mysql_fetch_array($result1);
if( $row1){
echo $row1['name'] ;
}
#HOPE THIS HELP YOU ALOT