我一般用iframe显示编辑数据库的内容,这样不用对回车换行进行特殊的处理,只要在读取数据库的时候将空白的符号替换成空就行了:)

解决方案 »

  1.   

    反转换
    function changestring($content)
    {
        $content = str_replace(""","\"",$content);
        $content = str_replace("&lt;","<",$content);
        $content = str_replace("&gt;",">",$content);
        $content = str_replace("&amp;","&",$content);
        Return $content;
    }
      

  2.   

    $target=nl2br(str_replace(" ",chr(127),htmlspecialchars($source));
      

  3.   

    用$text=ereg_replace($text)
    echo"$text";就可以了...如果不行..就说...
      

  4.   

    function txtToHtml($str)
    {
    $str = ereg_replace("&","&amp;",$str);
    $str = ereg_replace("\"","&quot;",$str);
    $str = ereg_replace("\'","&#039;",$str);
    $str = ereg_replace("<","&lt;",$str);
    $str = ereg_replace(">","&gt;",$str);
    $str = ereg_replace("\r\n","<br>",$str);
    return $str;
    }
    function htmlToTxt($str)
    {
    $str = ereg_replace("&amp;","&",$str);
    $str = ereg_replace("&quot;","\"",$str);
    $str = ereg_replace("&#039;","\'",$str);
    $str = ereg_replace("&lt;","<",$str);
    $str = ereg_replace("&gt;",">",$str);
    $str = ereg_replace("<br>","\r\n",$str);
    return $str;
    }
      

  5.   

    $target=nl2br(str_replace(" ",chr(127),htmlspecialchars($source));注:我的这个方法是用于POST原始数据存入数据库的,因为这样才方便于以后再次调出来编辑。如果你的项目不是定死要先将内容转成 HTML 的话,建议按照我这个方法去做。这样的话,用户输入的东西跟显示出来是一摸一样的。
      

  6.   

    就你用这个.没问题的..兄弟..$text=ereg_replace($text)
    echo"$text";就可以了...如果不行..就EMAIL给我[email protected]
      

  7.   

    nl2br(htmlspecialchars(addslashes("要存入数据库中的内容")));echo stripslashes("从数据库中取出的内容");
      

  8.   

    如果以上都不是你要的,那么这个可能对你有用$content = str_replace(chr(13),"<br>",$content);
      

  9.   

    str_replace("<br>","\r\n",$content);
      

  10.   

    function txtToEnter($str)
    {
    $str = ereg_replace(" ","&nbsp;",$str);
    $str = ereg_replace("\n","<br>",$str);
    return $str;
    }
    这个函数只在显示时用就可以了,这样用就行了txtToEnter(htmlspecialchars($Body)),一定好用,我用过!:)