我想要过滤一些html标签的属性,怎么写正则表达式啊,求举个例子
比如只允许有<a href="" title=""> <abbr title=""> 这两个个标签和属性

解决方案 »

  1.   

    <\/?(?:a|abbr)([^>]*?)>这样就可以得到<a href="" title=""> <abbr title=""> 这2个标签
      

  2.   

    <?php
    $a = "<cdsf><adsf><a>sdf</a> sd<html>sd</html>";
    $a = preg_replace('/<\/[^a][^>]*>/i', '', $a);
    $a = preg_replace('/<[^a][^\s][^>]*>/i', '', $a);
    $a = preg_replace('/<a[^\s][^>]*>/i', '', $a);
    echo htmlspecialchars($a);
      

  3.   

    strip_tags($string,'<a>,<abbr>')