Exemplo n.º 1
0
    private function test()
    {
        $string = <<<bbb
<p>关于开源访谈</p>
<p>&nbsp;<br />【作者简介】<br />栗元峰,开源爱好者。从iOS应用开发、cocos2d-iphone游戏开发到cocos2d-x游戏开发,参与了appstore排行榜单第一的《全民英雄》的开发,和其他多款上线成功项目。目前供职于http://9miao.com,专注于开源跨平台移动应用引擎CrossApp的开发。</p>
<p><br />&nbsp;<br />【软件简介】<br />CrossApp是一款免费、开源、跨平台的移动应用开发引擎,使用C++开发,基于OpenGL&nbsp;ES&nbsp;2.0渲染,可以帮助所有开发者快速的开发出跨平台的原生移动应用,支持导出包括IOS和Android等。</p>
        
bbb;
        echo XssFilter::filter($string);
    }
Exemplo n.º 2
0
 public static function format($message)
 {
     //替换h1-6和font
     $message = preg_replace('/\\<(h\\d|font)[^>]*?\\>(.*?)\\<(\\/\\1)\\>/is', '<p>\\2</p>', $message);
     //清除禁止标签
     $message = strip_tags($message, '<p><a><div><br><img><span><table><tbody><td><th><tr><ul><ol><li><b><em><strong>');
     //清除所有没加引号的属性
     //preg_match_all('/(?!\<\w+)\s+\w*\=\s*[^>\s\'"]*?\s/is', $message, $mat);print_r($mat);
     $message = preg_replace('/(?!\\<\\w+)\\s+\\w*\\=\\s*[^>\\s\'"]*?\\s/is', '', $message);
     //清除class和style和on事件,指定图片等宽和高的也要清空,手机不兼容
     //preg_match_all('/(?!\<\w+)\s+(?:on|style|class|color)\w*\=\s*[\'"][^\'\">]*[\'"]/is', $message, $mat);print_r($mat);
     $message = preg_replace('/(?!\\<\\w+)\\s+(?:on|style|class|color|width|height)\\w*\\=\\s*[\'"]?[^\'\\">]*[\'"]?/is', '', $message);
     //标签替换
     $message = str_ireplace(array('<em>', '</em>', '<strong>', '</strong>'), array('<b>', '</b>', '<b>', '</b>'), $message);
     //清除空白内容
     $message = preg_replace('/\\s*?\\<(?:p|span|b|div)\\>(\\&nbsp;|\\s)*?<\\/(?:p|span|b|div)\\>\\s*?/is', '', $message);
     //检测标签匹配情况
     //$message=self::matchTags($message);
     return XssFilter::filter($message);
 }