Php 带有sql中html标记的output varchar-output已编码,不应

Php 带有sql中html标记的output varchar-output已编码,不应,php,mysql,string,varchar,Php,Mysql,String,Varchar,正在将表单字段中的输入保存到sql数据库varchar255。。。输入类似于: <a href="test.com">Author Name</a> &lt;a href=&quot;test.com&quot;&gt;Author Name&lt;/a&gt; 由于这应该是作为html的回声,它不能正确地显示在页面上。也许我只是累了,但我不知道如何将其作为非编码输出,以便浏览器正确读取。尝试以下方法: <?php

正在将表单字段中的输入保存到sql数据库varchar255。。。输入类似于:

<a href="test.com">Author Name</a>
&lt;a href=&quot;test.com&quot;&gt;Author Name&lt;/a&gt;
由于这应该是作为html的回声,它不能正确地显示在页面上。也许我只是累了,但我不知道如何将其作为非编码输出,以便浏览器正确读取。

尝试以下方法:

<?php
    echo htmlspecialchars_decode("&lt;a href=&quot;test.com&quot;&gt;Author Name&lt;/a&gt;");
?>

为什么在插入数据库之前要对html标记进行编码?

这取决于如何将它们插入数据库…但无论如何,html\u entity\u decode或htmlspecialchars\u decode应该能够将它们转换回。html\u entity\u decode完成了这项工作…我知道有类似的事情,但什么都记不起来了。。。该睡觉了!谢谢
#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