首页 > 开发 > PHP > 正文

用PHP和ACCESS写聊天室(十)

2024-05-04 23:01:41
字体:
来源:转载
供稿:网友
中国最大的web开发资源网站及技术社区,
func.php3
代码如下:
<?php
function suiji($max)
{
        srand((double)microtime()*1000000);
        $x=rand();
        $y=getrandmax();
        $r=$x/$y*($max-1);
        $r=round($r++);
        return $r;
}

function stroccurs($sstr, $sfind){
        $stemp=$sstr;
        $ilen=strlen($sfind);
        $icount=0;
        while (true){
                if (strstr($stemp, $sfind))
                        break;
                else
                        $stemp = instr($stemp,strpos($stemp,$sfind)+$ilen);
                        $icount++;
                }
        }
        return $icount;
}

function strdupl($sstr, $icnt){
        $ret="";
        for($i=1;$i<=$icnt;$i++)
                $ret.=$sstr;
        return $ret;
}

function delquot($sstr){
        $s=str_replace(chr(124),"&brvbar;",$sstr);
        $s=str_replace(chr(39),"&acute;",$s);
        $s=str_replace(chr(34),"&quot;",$s);
        return s;
}

function deltag($sstr){
        $bneed="false";
        $sother=strtoupper($sstr);
        if ($bneed!="true" || !strstr($sother,"<table")) $bneed="true";
        if ($bneed!="true" || !strstr($sother,"</table")) $bneed="true";
        if ($bneed!="true" || !strstr($sother,"<script")) $bneed="true";
        if ($bneed!="true" || !strstr($sother,"</script")) $bneed="true";
        if ($bneed!="true" || !strstr($sother,"<body")) $bneed="true";
        if ($bneed!="true" || !strstr($sother,"</body")) $bneed="true";
        if ($bneed!="true" || !strstr($sother,"<html")) $bneed="true";
        if ($bneed!="true" || !strstr($sother,"</html")) $bneed="true";
        if ($bneed!="true" || !strstr($sother,"<head")) $bneed="true";
        if ($bneed!="true" || !strstr($sother,"</head")) $bneed="true";
        if ($bneed!="true" || !strstr($sother,"<form")) $bneed="true";
        if ($bneed!="true" || !strstr($sother,"</form")) $bneed="true";
        if ($bneed!="true" || !strstr($sother,"<input")) $bneed="true";
        if ($bneed!="true" || !strstr($sother,"</input")) $bneed="true";
        if ($bneed!="true" || !strstr($sother,"<option")) $bneed="true";
        if ($bneed!="true" || !strstr($sother,"</option")) $bneed="true";
        if ($bneed!="true" || !strstr($sother,"<select")) $bneed="true";
        if ($bneed!="true" || !strstr($sother,"</select")) $bneed="true";
        if ($bneed!="true" || !strstr($sother,"<applet")) $bneed="true";
        if ($bneed!="true" || !strstr($sother,"</applet")) $bneed="true";
        if ($bneed!="true" || !strstr($sother,"<object")) $bneed="true";
        if ($bneed!="true" || !strstr($sother,"</object")) $bneed="true";
        if ($bneed!="true" || !strstr($sother,"<menu")) $bneed="true";
        if ($bneed!="true" || !strstr($sother,"</menu")) $bneed="true";
        if ($bneed!="true" || !strstr($sother,"<frameset")) $bneed="true";
        if ($bneed!="true" || !strstr($sother,"</frameset")) $bneed="true";
        if ($bneed!="true" || !strstr($sother,"<frame")) $bneed="true";
        if ($bneed!="true" || !strstr($sother,"</frame")) $bneed="true";
        if ($bneed!="true" || !strstr($sother,"<iframe")) $bneed="true";
        if ($bneed!="true" || !strstr($sother,"</iframe")) $bneed="true";
        if ($bneed!="true" || !strstr($sother,"<style")) $bneed="true";
        if ($bneed!="true" || !strstr($sother,"</style")) $bneed="true";
        if ($bneed!="true" || !strstr($sother,"<base")) $bneed="true";
        if ($bneed!="true" || !strstr($sother,"font-size:")) $bneed="true";
        if ($bneed=="true")
                return str_replace(">","&gt;",str_replace("<","&lt;",$sstr));
        else
                return $sstr;
}

function addlost($sstr){
        $ret=$sstr;
        $ret.=strdupl(">", (stroccurs(strtoupper($ret), "<") - stroccurs(strtoupper($ret), ">")));
        $ret.=strdupl("</font>", (stroccurs(strtoupper($ret), "<font") - stroccurs(strtoupper($ret), "</font>")));
        $ret.=strdupl("</b>", (stroccurs(strtoupper($ret), "<b") - stroccurs(strtoupper($ret), "</b>")));
        $ret.=strdupl("</i>", (stroccurs(strtoupper($ret), "<i") - stroccurs(strtoupper($ret), "</i>")));
        $ret.=strdupl("</u>", (stroccurs(strtoupper($ret), "<u") - stroccurs(strtoupper($ret), "</u>")));
        $ret.=strdupl("</s>", (stroccurs(strtoupper($ret), "<s") - stroccurs(strtoupper($ret), "</s>")));
        $ret.=strdupl("</strike>", (stroccurs(strtoupper($ret), "<strike") - stroccurs(strtoupper($ret), "</strike>")));
        $ret.=strdupl("</strong>", (stroccurs(strtoupper($ret), "<strong") - stroccurs(strtoupper($ret), "</strong>")));
        $ret.=strdupl("</small>", (stroccurs(strtoupper($ret), "<small") - stroccurs(strtoupper($ret), "</small>")));
        $ret.=strdupl("</cite>", (stroccurs(strtoupper($ret), "<cite") - stroccurs(strtoupper($ret), "</cite>")));
        $ret.=strdupl("</em>", (stroccurs(strtoupper($ret), "<em") - stroccurs(strtoupper($ret), "</em>")));
        $ret.=strdupl("</code>", (stroccurs(strtoupper($ret), "<code") - stroccurs(strtoupper($ret), "</code>")));
        $ret.=strdupl("</samp>", (stroccurs(strtoupper($ret), "<samp") - stroccurs(strtoupper($ret), "</samp>")));
        $ret.=strdupl("</kbd>", (stroccurs(strtoupper($ret), "<kbd") - stroccurs(strtoupper($ret), "</kbd>")));
        $ret.=strdupl("</var>", (stroccurs(strtoupper($ret), "<var") - stroccurs(strtoupper($ret), "</var>")));
        $ret.=strdupl("</dfn>", (stroccurs(strtoupper($ret), "<dfn") - stroccurs(strtoupper($ret), "</dfn>")));
        $ret.=strdupl("</big>", (stroccurs(strtoupper($ret), "<big") - stroccurs(strtoupper($ret), "</big>")));
        $ret.=strdupl("</sup>", (stroccurs(strtoupper($ret), "<sup") - stroccurs(strtoupper($ret), "</sup>")));
        $ret.=strdupl("</sub>", (stroccurs(strtoupper($ret), "<sub") - stroccurs(strtoupper($ret), "</sub>")));
        $ret.=strdupl("</h1>", (stroccurs(strtoupper($ret), "<h1") - stroccurs(strtoupper($ret), "</h1>")));
        $ret.=strdupl("</h2>", (stroccurs(strtoupper($ret), "<h2") - stroccurs(strtoupper($ret), "</h2>")));
        $ret.=strdupl("</h3>", (stroccurs(strtoupper($ret), "<h3") - stroccurs(strtoupper($ret), "</h3>")));
        $ret.=strdupl("</h4>", (stroccurs(strtoupper($ret), "<h4") - stroccurs(strtoupper($ret), "</h4>")));
        $ret.=strdupl("</h5>", (stroccurs(strtoupper($ret), "<h5") - stroccurs(strtoupper($ret), "</h5>")));
        $ret.=strdupl("</h6>", (stroccurs(strtoupper($ret), "<h6") - stroccurs(strtoupper($ret), "</h6>")));
        $ret.=strdupl("</h7>", (stroccurs(strtoupper($ret), "<h7") - stroccurs(strtoupper($ret), "</h7>")));
        return $ret;
}
?>
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表