Sep 15

去掉非法HTML + Blog字符串截取 不指定

bkkkd , 16:09 , 开发应用 , 评论(0) , 引用(0) , 阅读(3678) , Via 本站原创 | |

<?

/*+++++++++++++++++++++++++

名称: stripBadHtml()

功能: 去掉非法HTML

作者: 朱武杰(纯粹误会 QQ:44922032)

参数: content  字符串  引用的

返回: content

使用:

++++++++++++++++++++++++++*/

function stripBadHtml (&$content)

{

    return
$content =preg_Replace(

        array(

            
"!<([/]?)(htm|head|body|meta)(.+?)?>!is",

            
"!<style(.+?)?>(.+?)?</style>!is",

            
"!<script(.+?)?>(.+?)?</script>!is",

            
"/javascript/i",

            
"/value/i",

            
"/form/i",

            
"/(about|file):/i",

            
"/document.cookie/i",

            
"/title/i",

            
'/on([a-z]+)([ ]+)=/i'

        
) ,

        array(

            
'',

            
'',

            
'',

            
'',

            
"&#106avascript",

            
"&#118alue",

            
"&#102orm",

            
"$1&#58",

            
"documents&#46cookie",

            
"&#116itle",

            
'&#111n$1$2='

        
),

        
$content

    
);

}



//----------裁剪字串函数----------//

function SubstrCn($str,$len,$dot=1){

    if(
strlen($str)<=$len)return $str;

    
$parity=0;

    for(
$i=$len-1;$i>=0;$i--)if(ord(substr($str,$i,1))>127)$parity++;else break;

    
$len-=$parity%2;

    return
substr($str,0,$len).($dot?"...":"");

}





/*

名称: BlogSubstr()

功能: Blog字符串截取

作者: 朱武杰(纯粹误会 QQ:44922032)

参数: string 要被节取的字符串 length 截取的长度

返回: 数组(icon=>小图标,content=>截取后的内容)

时间: 2005-9-12

*/

function BlogSubstr($string,$length)

{

    
$icon='';

    
$imagePath="de/de_images/popups";

    if(
eregi("<img ",$string))

    {

        
$icon.="<img src=\"$imagePath/image.gif\"  alt=图片 align=absmiddle>";

    }

    if(
eregi("<embed ([^>]+)?media",$string))

    {

        
$icon.="<img src=\"$imagePath/media.gif\" alt=媒体 align=absmiddle>";

    }

    if(
eregi("<embed ([^>]+)?flash",$string))

    {

        
$icon.="<img src=\"$imagePath/flash.gif\" alt=Flash align=absmiddle>";

    }

    if(
eregi("<embed ([^>]+)?real",$string))

    {

        
$icon.="<img src=\"$imagePath/real.gif\" alt=RealOne align=absmiddle>";

    }



    
$string=SubstrCn(strip_tags($string),$length);



    return array(
'icon'=>$icon,'content'=>$string);

}

?>

发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]