一个变量的值输出是:  
<P>&nbsp;&nbsp;&nbsp; 据亚豪机构统计数据显示</p>我想让其只输出 (中文部分): 据亚豪机构统计数据显示
怎么实现呀,thanks

解决方案 »

  1.   

    输出到html上面显示出来不是只有中文了吗?
      

  2.   


    <?php
    $str = '<P>&nbsp;&nbsp;&nbsp; 据亚豪机构&nbsp;&nbsp;统计数据显示 </p> ';
    echo '<textarea>';
    echo trim(str_replace('&nbsp;','',strip_tags($str)));
    echo '</textarea>';
    exit;
    ?>
      

  3.   

    //去除HTML标签
    function removehtml($str="")
    {
    if(!empty($str))
    {
    $reg = "/<(.)+>/Uim";
    return preg_replace($reg,"",$str);
    }
    }如果需要把&nbsp;去掉就加上str_replace("&nbsp;","",$str)
      

  4.   

    $body=htmlspecialchars_decode($row_h['body'], ENT_QUOTES);
    $body=strip_tags($body);
    $body=str_replace("&nbsp;","",$body);
    $body=str_replace("&#8226;","",$body);
    $body=str_replace("&ldquo;","",$body);
    $body=str_replace("&rdquo;","",$body);
    $body=str_replace("★","",$body);
    $body=str_replace("☆","",$body);
      

  5.   

    $document="&lt;P&gt;&amp;nbsp; &lt;/P&gt;
    &lt;P&gt;南昌市新建商品房交易情况 &lt;/P&gt;
    &lt;P&gt;套数122&lt;/P&gt;
    &lt;P&gt;面积12543.52&lt;/P&gt;
    &lt;P&gt;南昌市二手房(存量房)交易情况&lt;/P&gt;
    &lt;P&gt;套数96&lt;/P&gt;
    &lt;P&gt;面积8592.80&lt;/P&gt;
    &lt;P&gt;南昌县新建商品房交易情况&lt;/P&gt;
    &lt;P&gt;住宅套数73.00&lt;/P&gt;
    &lt;P&gt;住宅面积6238.66&lt;/P&gt;
    &lt;P&gt;住宅均价2943.16&lt;/P&gt;
    &lt;P&gt;非住宅套数2.00&lt;/P&gt;
    &lt;P&gt;非住宅面积27.84&lt;/P&gt;
    &lt;P&gt;住宅均价1606.43&lt;/P&gt;
    &lt;P&gt;南昌县二手房(存量房)交易情况&amp;nbsp; &lt;/P&gt;
    &lt;P&gt;套数25&lt;/P&gt;
    &lt;P&gt;面积1895.59&lt;/P&gt";
    //echo $document;
    $search = array ("'<script[^>]*?>.*?</script>'si", // 去掉 javascript
                     "'<[\/\!]*?[^<>]*?>'si",           // 去掉 HTML 标记
                     "'([\r\n])[\s]+'",                 // 去掉空白字符
                     "'&(quot|#34);'i",                 // 替换 HTML 实体
                     "'&(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");                    // 作为 PHP 代码运行$replace = array ("",
                      "",
                      "\\1",
                      "\"",
                      "&",
                      "<",
                      ">",
                      " ",
                      chr(161),
                      chr(162),
                      chr(163),
                      chr(169),
                      "chr(\\1)");$text = preg_replace ($search, $replace, $document);
    $text=strip_tags($text);
    echo $text;