输出显示转义的引号

时间:2013-06-28 09:01:26

标签: php pdo

在使用params并将数据插入数据库之后,配额转义为\",因此输出看起来很丑陋,如:hello this is an output test \"test \"
如何使引号正常显示?

这是我如何向DB插入数据。

if( $_POST )
{
   include "db.php";

    $title = $_POST['title'];
    $content = $_POST['content'];

    if(strlen($title) >= 77) { die('large_title'); };
    if(strlen($content) <= 19) { die('low_content'); };
    if(empty($title)) { $title = 'EMPTY00'; }

 $stmt = $mysqli->prepare("INSERT INTO na_posts(title,content) VALUES (?, ?)");
 $stmt->bind_param("ss",$title,$content);
 $stmt->execute();
 $stmt->close();

      $content = htmlspecialchars(mb_substr($content, 0, 125,'utf-8'));
      echo $content.'...';
} else { die('error'); }

这是我的输出代码:

$content = nl2br(htmlspecialchars($row->content));
echo $content;

2 个答案:

答案 0 :(得分:1)

使用stripslashes

$content = nl2br(stripslashes(htmlspecialchars($row->content)));
echo $content;

答案 1 :(得分:1)

当您在数据库中插入数据时,有些代码会添加不必要的斜杠。

在代码中的某处是magic_quotes或某种addslashes()/ mysql_real_escape_string()。 摆脱其中任何一个。

相关问题