1

我似乎很难显示 HTML。哈哈,让我解释一下。

我有 1 个用于“评论”的模板文件......它在 html 中告诉了去哪里等等。添加、更新和选择任何“评论”时

IE:

<div class='comment'>
   <div>{$name}</div>
   <div>{$comment}</div>
</div>

所以在我的评论中,我需要从数据库中提取评论,其中包括,\n

所以我就这样走了。

$comment = nl2br($comment);
<div class='comment'>
   <div>{$name}</div>
   <div>{$comment}</div>
</div>

这确实有效......但是当我通过 jQuery 进行更新时,我使用,

$("#"+ target +"").replaceWith(responseText);

并且 responseText 包括所有 HTML ...但出于某种原因,它仍然包括 \n... 而不是

我不知道这是 Javascript 的限制还是渲染问题。只是不知道还能去哪里……有什么想法吗?

4

2 回答 2

0

嗯,这有点奇怪,有些问题我没有完全测试,很抱歉可能没有澄清。但是 mysql_real_escape_string() 导致 \n 存储在数据库中的问题。

我正在考虑使用此功能。在 php.net 的网站上找到

function mysql_escape_mimic($value) {
        if(isset($value)) 
        {
            if(is_array($value)) {
                return array_map(__METHOD__, $value);
            }

            if(!empty($value) && is_string($value)) {
                //return str_replace( array('\\',   "\0",  "\n",  "\r",   "'",  '"',  "\x1a"), 
                //                  array('\\\\', '\\0', '\\n', '\\r', "\\'", '\\"', '\\Z'), $value);

                return str_replace( array('\\',   "\0",  "\r",   "'",  '"',  "\x1a"), 
                                    array('\\\\', '\\0', '\\r', "\\'", '\\"', '\\Z'), $value);
            }

            return $value;
        }
    }
于 2011-07-12T05:29:18.773 回答
0

在 php 文件中,您正在使用 jQuery 获取注释,在回显数据之前尝试执行以下操作

$comment=str_replace('\n\r', '<br />', $comment);
$comment=str_replace('\n', '<br />', $comment);
echo $comment;
于 2011-07-11T22:03:34.373 回答