function dealSpecialChars($str){
  $str=str_replace(" "," ",htmlspecialchars($str));
  return str_replace("\n","<BR>",$str);
}

解决方案 »

  1.   

    br2nl
    nl2br
    .......
    还有php有没有叫htmlencode的函数?试试看吧:)gl
      

  2.   

    htmlencode好象是asp里的吧??php里好象是htmlspecialchars或htmlentitlesto;wasy(嘻嘻哈哈)
    你的哪个函数果真没什么bug了吗,能经受任何考验吗??
    我去试试先~~~:)
      

  3.   

    这个函数只能用于显示
    如果用于放在textarea或者text里面再行更改的话,这个函数还要修改
      

  4.   

    用于修改的话,不要替换\n对了,忘记告诉你前提条件,可能有的版本的php会自动给特殊符号加上\
    所以你要在php.ini里面禁止掉这个功能:
    设置magic_quotes_gpc=off
      

  5.   

    htmlspecialchars最好自己写
    $str=str_replace("<","&lt;",$str);
    ........
      

  6.   

    function format_text($text, $html = 0, $word_wrap = 0, $bbcode = 0, $bbcode_img = 0) {
      $text = stripslashes(trim($text));  if ($word_wrap && $text != "") {
        $text = preg_replace("/([^\n\r ?&\.\/<>\"\\-]{".$word_wrap."})/i", " \\1\n", $text);
      }  if ($html != 1) {
        $text = str_replace("&lt;", "&amp;lt;", $text);
        $text = str_replace("&gt;", "&amp;gt;", $text);
        $text = str_replace("<", "&lt;", $text);
        $text = str_replace(">", "&gt;", $text);
      }
      $text = str_replace("\n", "<br />", $text);
      $text = replace_url($text);  if ($bbcode == 1) {
        $search_array = array(
          "/(\[)(list)(=)(['\"]?)([^\"']*)(\\4])(.*)(\[\/list)(((=)(\\4)([^\"']*)(\\4]))|(\]))/siU",
          "/(\[)(list)(])(.*)(\[\/list\])/siU",
          "/(\[\*\])/siU",
          "/(\[)(url)(=)(['\"]?)(www\.)([^\"']*)(\\4])(.*)(\[\/url\])/siU",
          "/(\[)(url)(=)(['\"]?)([^\"']*)(\\4])(.*)(\[\/url\])/siU",
          "/(\[)(url)(])(www\.)([^\"]*)(\[\/url\])/siU",
          "/(\[)(url)(])([^\"]*)(\[\/url\])/siU",
          "/(\[)(code)(])(\r\n)*(.*)(\[\/code\])/siU",
          "/javascript:/si",
          "/about:/si"
        );
        $replace_array = array(
          "<ol type=\"\\5\">\\7</ol>",
          "<ul>\\4</ul>",
          "<li>",
          "<a href=\"http://www.\\6\" target=\"_blank\">\\8</a>",
          "<a href=\"\\5\" target=\"_blank\">\\7</a>",
          "<a href=\"http://www.\\5\" target=\"_blank\">www.\\5</a>",
          "<a href=\"\\4\" target=\"_blank\">\\4</a>",
          "<pre>Code:<hr size=1>\\5<hr size=1></pre>",
          "java script:",
          "about :"
        );
        $text = preg_replace($search_array, $replace_array, $text);
        if (!$bbcode_img)  {
          $text = preg_replace("/(\[)(img)(])(\r\n)*([^\"]*)(\[\/img\])/siU", "<a href=\"\\5\" target=\"_blank\">\\5</a>", $text);
        }
        else  {
          $text = preg_replace("/(\[)(img)(])(\r\n)*([^\"]*)(\[\/img\])/siU", "<img src=\"\\5\">", $text);
        }
        $text = preg_replace("/(\[)(b)(])(\r\n)*([^\"]*)(\[\/b\])/siU", "<b>\\5</b>", $text);
        $text = preg_replace("/(\[)(i)(])(\r\n)*([^\"]*)(\[\/i\])/siU", "<i>\\5</i>", $text);
        $text = preg_replace("/(\[)(u)(])(\r\n)*([^\"]*)(\[\/u\])/siU", "<u>\\5</u>", $text);
      }
      $text = str_replace("\\'", "'", $text);
      
      return replace_badwords($text);
    }
      

  7.   

    哈哈,楼上的连UBB(VBB?)都解决了