你想要的结果是什么样子的呢?参考手册这一章或许对你有帮助:
http://cn2.php.net/manual/zh/faq.html.php

解决方案 »

  1.   

    $str = '原始数据';
    [code=PHP]
    //得到除了链接外的转化文本
    $str = preg_replace(
        array("'([\r\n])[\s]+'",
              "'&(quot|#34);'i",
              "'&(amp|#38);'i",
              "'&(lt|#60);'i",
              "'&(gt|#62);'i",
              "'&(nbsp|#160);'i",
              "'&(iexcl|#161);'i",
              "'&(cent|#162);'i",
              "'&(pound|#163);'i",
              "'&(copy|#169);'i",
              "'&#(\d+);'e"),
        array("\\1",
              "\"",
              "&",
              "<",
              ">",
              " ",
              chr(161),
              chr(162),
              chr(163),
              chr(169),
              "chr(\\1)"),
        strip_tags($str, '<a>'));
    //2、用mb_substr或类似的函数截取即可
    [/php]
      

  2.   


    //得到除了链接外的转化文本
    $str   =   preg_replace(
            array("'([\r\n])[\s]+'",
                        "'&(quot ¦#34);'i",
                        "'&(amp ¦#38);'i",
                        "'&(lt ¦#60);'i",
                        "'&(gt ¦#62);'i",
                        "'&(nbsp ¦#160);'i",
                        "'&(iexcl ¦#161);'i",
                        "'&(cent ¦#162);'i",
                        "'&(pound ¦#163);'i",
                        "'&(copy ¦#169);'i",
                        "'&#(\d+);'e"),
            array("\\1",
                        "\"",
                        "&",
                        " <",
                        "> ",
                        "   ",
                        chr(161),
                        chr(162),
                        chr(163),
                        chr(169),
                        "chr(\\1)"),
            strip_tags($str,   ' <a> '));
    //2、用mb_substr或类似的函数截取即可
      

  3.   

    ..... 不好意思,那个正则没看懂,麻烦帮我看下怎么改下面的代码吧?$str = '<img src="a.gif" /><a href="a.html">a</a>asdfsdfsdf';
    echo  mb_strcut($str, 0, 20, 'utf-8'); 怎么给回复的人加分??