PHP+;PDO,我的转义字符赢了';显示时不显示
首先,我想道歉,我还是个初学者 出于学习目的,我正在创建一个博客引擎,我刚刚注意到,当我列出注释时,转义字符(如回车键)会正确地显示在数据库中,但在显示注释时仅显示空白字符 我正在使用PostgreSQL 8.3 在这里,您可以看到一个示例数据库条目:PHP+;PDO,我的转义字符赢了';显示时不显示,php,postgresql,pdo,Php,Postgresql,Pdo,首先,我想道歉,我还是个初学者 出于学习目的,我正在创建一个博客引擎,我刚刚注意到,当我列出注释时,转义字符(如回车键)会正确地显示在数据库中,但在显示注释时仅显示空白字符 我正在使用PostgreSQL 8.3 在这里,您可以看到一个示例数据库条目: fema=> select * from comments where id = 54; -[ RECORD 1 ]------------------------- id | 54 authorid | 1 text
fema=> select * from comments where id = 54;
-[ RECORD 1 ]-------------------------
id | 54
authorid | 1
text | This new line won't show.\r
: No\r
: \r
: new\r
: \r
: \r
: \r
: lines.
time | 1341417673
postid | 15
answerid | 0
在这里,您可以看到var_dump()显示的内容:
这就是我获取数据的方式:
$stmt = db::$db->prepare("select comments.id as commentid ,authorid,text,time,postid,answerid,users.* from comments left join users on users.id = comments.authorId where postid = :postId");
$stmt->execute(array('postId' => $_GET['p']));
$commentRslt = $stmt->fetchAll();
然后foreach对它们进行迭代,并替换我用来标识必须替换的对象的标记:
$currComment = str_replace('{{{cms:comment:text}}}', $commentRslt[$key]['text'], $currComment);
以下是我将新注释插入DB的方式:
$stmt = self::$db->prepare('INSERT INTO comments (authorId, text, time, postId, answerId) VALUES (:authorId, :text, :time, :postId, :answerId)');
$stmt->execute(array( 'authorId' => $_SESSION['userId'],
'text' => str_replace(array('<','>'), array('<','>'), isset($_POST['newCommentArea']) ? $_POST['newCommentArea'] : $_SESSION['newCommentArea']),
'time' => time(),
'postId' => isset($_POST['commentNew']) ? $_POST['commentNew' ] : $_SESSION['postId'],
'answerId' => $answerId));
$stmt=self::$db->prepare('INSERT-INTO-comments(authorId,text,time,postId,answerId))值(:authorId,:text,:time,:postId,:answerId)');
$stmt->execute(数组('authorId'=>$\u会话['userId'],
'text'=>str_replace(数组(''),数组('<','>'),isset($_POST['newCommentArea'])?$_POST['newCommentArea']:$_SESSION['newCommentArea']),
'time'=>time(),
'postId'=>isset($_POST['commentNew'])?$_POST['commentNew']:$_SESSION['postId'],
‘answerId’=>$answerId));
很抱歉有这么多代码示例,但我甚至不知道问题出在哪里,我想彻底了解一下
有谁能告诉我怎么解决这个问题吗?只要告诉我是哪里出的错就好了。我真的不知道
谢谢。这里没有猜测,但是:
HTML/浏览器将连续空白折叠为单个空格。如果要保留换行符,请使用。在此处进行猜测,但:
HTML/浏览器将连续空白折叠为单个空格。如果您想保留换行符,请使用
标记替换换行符。谢谢,现在可以使用了。没想到会这么容易。:)谢谢,现在可以用了。没想到会这么容易。:)
$stmt = self::$db->prepare('INSERT INTO comments (authorId, text, time, postId, answerId) VALUES (:authorId, :text, :time, :postId, :answerId)');
$stmt->execute(array( 'authorId' => $_SESSION['userId'],
'text' => str_replace(array('<','>'), array('<','>'), isset($_POST['newCommentArea']) ? $_POST['newCommentArea'] : $_SESSION['newCommentArea']),
'time' => time(),
'postId' => isset($_POST['commentNew']) ? $_POST['commentNew' ] : $_SESSION['postId'],
'answerId' => $answerId));