duannue2455 2011-07-11 21:55
浏览 35
已采纳

使用Javascript处理从数据库到HTML的NL2BR

I am having difficulty with displaying HTML it seems. haha, let me explain.

I have 1 template file for "comments"... and it tells things where to go and such in the html. When Adding, Updating and Selecting any of the "comments"

IE:

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

So within my comment I need to pull the COMMENT from the database which includes,

So I go like this.

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

And this does work... But when I do an UPDATE via jQuery I use,

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

And the responseText includes all HTML... but some reason, it still is including the ... and not

I don't know if this is a limitation with Javascript, or rendering issues. Just not sure where else to go here...Any thoughts?

  • 写回答

2条回答 默认 最新

  • dongyu9894 2011-07-12 05:29
    关注

    Well this was a tad strange, there was some issues that I didn't fully test and sorry for maybe not clarifying. But mysql_real_escape_string() was causing issues with the being stored in the database.

    There for I am looking at using this function instead. Found on php.net's website

    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",  "
    ",  "",   "'",  '"',  "\x1a"), 
                    //                  array('\\\\', '\\0', '\
    ', '\', "\\'", '\\"', '\\Z'), $value);
    
                    return str_replace( array('\\',   "\0",  "",   "'",  '"',  "\x1a"), 
                                        array('\\\\', '\\0', '\', "\\'", '\\"', '\\Z'), $value);
                }
    
                return $value;
            }
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值