这里发言,表示您接受了CSDN论坛的用户<a href="www.baidu.com">行为准则</a>
请对您的言行负责,并遵守中华人民共和国有关法律法规,尊重网上道德。
转载文章请注明出自“CSDN(www.csdn.net)”。如是商业用途请联系原作者。怎么把a标记去掉,只留下行为准则。小弟先谢谢了

解决方案 »

  1.   

     public function strip_selected_tags($text, $tags = array())
       {
           $args = func_get_args();
           $text = array_shift($args);
           $tags = func_num_args() > 2 ? array_diff($args,array($text))  : (array)$tags;
           foreach ($tags as $tag){
               if(preg_match_all('/<'.$tag.'[^>]*>(.*)<\/'.$tag.'>/iU', $text, $found)){
                   $text = str_replace($found[0],$found[1],$text);
             }
           }       return $text;
       }
    $text = '<a href="www.baidu.com">行为准则</a>的撒的发的是发烧的发的';
    echo strip_tags($text);
    echo strip_tags($text, '<a>');
      

  2.   

    给你个正则入门教程看看
    http://www.regexlab.com/zh/regref.htm
      

  3.   

    http://baike.baidu.com/view/4126659.htm
    strip_tags() 函数剥去 HTML、XML 以及 PHP 的标签。
      

  4.   

    我这个里面还有一些其他未知的html标记会出现的。这里只是随便举个列子。
      

  5.   

    正则就可以了,
    $str='<a href="www.baidu.com">行为准则</a>';
    echo preg_replace("/<a (.*)>(.*)<\/a>/iU",'\2',$str);
      

  6.   

    /<a[^>]*>(.*?)<\/a>/ig
    即使内容是“行为>准则”也不会出错。.*?可以避免正则回溯,提高匹配效率。