|
<br> 这个类可以用来检查URL地址的合法性,目前支持ftp,file,http,https,gopher,news,nntp,telnet,wais.<BR> 功能: 检查URL的合法性 <BR><BR>技术资料: <BR>Uniform Resource Locators (URL) <BR>http://info.internet.isi.edu/in-notes/rfc/files/rfc1738.txt <BR>Regex edition 0.12a <BR>http://www.cs.utah.edu/dept/old/texinfo/regex/regex_toc.html <BR>*/ <BR>class urlcheck{ <BR>var $regex = array(//协议名(注意在这里必须写成小写) => 对应的正则表达式 <BR>"ftp" => "$this->ftpurl", <BR>"file" => "$this->fileurl", <BR>"http" => "$this->httpurl", <BR>"https" => "$this->httpurl", <BR>"gopher" => "$this->gopherurl", <BR>"news" => "$this->newsurl", <BR>"nntp" => "$this->nntpurl", <BR>"telnet" => "$this->telneturl", <BR>"wais" => "$this->waisurl" <BR>); <BR><BR><BR><BR>var $lowalpha; <BR>var $hialpha; <BR>var $alpha; <BR>var $digit; <BR>var $safe; <BR>var $extra; <BR>var $national; <BR>var $punctuation; <BR>var $reserved; <BR>var $hex; <BR>var $escape; <BR>var $unreserved; <BR>var $uchar; <BR>var $xchar; <BR>var $digits; <BR><BR><BR><BR>var $urlpath; <BR>var $password; <BR>var $user; <BR>var $port; <BR>var $hostnumber; <BR>var $alphadigit; <BR>var $toplabel; <BR>var $domainlabel; <BR>var $hostname; <BR>var $host; <BR>var $hostport; <BR>var $login; <BR><BR><BR><BR>//ftp <BR>var $ftptype; <BR>var $fsegment; <BR>var $fpath; <BR>var $ftpurl; <BR><BR><BR><BR>//file <BR>var $fileurl; <BR><BR><BR><BR>//http,https <BR>var $search; <BR>var $hsegment; <BR>var $hpath; <BR>var $httpurl; <BR><BR><BR><BR>//gopher <BR>var $gopher_string; <BR>var $selector; <BR>var $gtype; <BR>var $gopherurl; <BR><BR><BR><BR>//news <BR>var $article; <BR>var $group; <BR>var $grouppart; <BR>var $newsurl; <BR><BR><BR><BR>//nntp <BR>var $nntpurl; <BR><BR><BR><BR>//telnet <BR>var $telneturl; <BR><BR><BR><BR>//wais <BR>var $wpath; <BR>var $wtype; <BR>var $database; <BR>var $waisdoc; <BR>var $waisindex; <BR>var $waisdatabase; <BR>var $waisurl; <BR><BR><BR><BR>function check($url){ <BR>$pos = @strpos($url,":",1); <BR>if($pos<1) return false; <BR>$prot = substr($url,0,$pos); <BR>if(!isset($this->regex[$prot])) return false; <BR>eval("$regex = ".$this->regex[$prot].";"); <BR>return ereg("^".$regex."$",$url); <BR>} <BR><BR><BR><BR>function urlcheck(){ <BR>$this->lowalpha = "[a-z]"; <BR>$this->hialpha = "[A-Z]"; <BR>$this->alpha = "(".$this->lowalpha."|".$this->hialpha.")"; <BR>$this->digit = "[0-9]"; <BR>$this->safe = "[$.+_-]"; <BR>$this->extra = "[*()\"!,]"; <BR>$this->national = "([{}|\^~`]|\\[|\\])"; <BR>$this->punctuation = "[<>#%"]"; <BR>$this->reserved = "[?;/ &=]"; <BR>$this->hex = "(".$this->digit."|[a-fA-F])"; <BR>$this->escape = "(%".$this->hex."{2})"; <BR>$this->unreserved = "(".$this->alpha."|".$this->digit."|".$this->safe."|".$this->extra.")"; <BR>$this->uchar = "(".$this->unreserved."|".$this->escape.")"; <BR>$this->xchar = "(".$this->unreserved."|".$this->reserved."|".$this->escape.")"; <BR>$this->digits = "(".$this->digit."+)"; <BR><BR><BR><BR>$this->urlpath = "(".$this->xchar."*)"; <BR>$this->password = "((".$this->uchar."|[?;&=]".")*)"; <BR>$this->user = "((".$this->uchar."|[?;&=]".")*)"; <BR>$this->port = $this->digits; <BR>$this->hostnumber = "(".$this->digits.".".$this->digits.".".$this->digits.".".$this->digits.")"; <BR>$this->alphadigit = "(".$this->alpha."|".$this->digit.")"; <BR>$this->toplabel = "(".$this->alpha."|(".$this->alpha."(".$this->alphadigit."|-)*".$this->alphadigit."))"; <BR>$this->domainlabel = "(".$this->alphadigit."|(".$this->alphadigit."(".$this->alphadigit."|-)*".$this->alphadigit."))"; <BR>$this->hostname = "((".$this->domainlabel."\\.)*".$this->toplabel.")"; <BR>$this->host = "(".$this->hostname."|".$this->hostnumber.")"; <BR>$this->hostport = "(".$this->host."(:".$this->port.")?)"; <BR>$this->login = "((".$this->user."(:".$this->password.")?@)?".$this->hostport.")"; <BR><BR><BR><BR>$this->ftptype = "[aidAID]"; <BR>$this->fsegment = "((".$this->uchar."|[? &=])*)"; <BR>$this->fpath = "(".$this->fsegment."(/".$this->fsegment.")*)"; <BR>$this->ftpurl = "([fF][tT][pP]://".$this->login."(/".$this->fpath."(;[tT][yY][pP][eE]=".$this->ftptype.")?)?)"; <BR><BR><BR><BR>$this->fileurl = "([fF][iI][lL][eE]://(".$this->host."|[lL][oO][cC][aA][lL][hH][oO][sS][tT])?/".$this->fpath.")"; <BR><BR><BR><BR>$this->search = "((".$this->uchar."|[; &=])*)"; <BR>$this->hsegment = "((".$this->uchar."|[; &=])*)"; <BR>$this->hpath = "(".$this->hsegment."(/".$this->hsegment.")*)"; <BR>$this->httpurl = "([hH][tT][tT][pP][sS]?://".$this->hostport."(/".$this->hpath."([?]".$this->search.")?)?)"; <BR><BR><BR><BR>$this->gopher_string = "(".$this->xchar."*)"; <BR>$this->selector = "(".$this->xchar."*)"; <BR>$this->gtype = $this->xchar; <BR>$this->gopherurl = "([gG][oO][pP][hH][eE][rR]://".$this->hostport."(/(".$this->gtype."(".$this->selector."(%09".$this->search."(%09".$this->gopher_string.")?)?)?)?)?)"; <BR><BR><BR><BR>$this->article = "((".$this->uchar."|[;/?:&=])+@".$this->host.")"; <BR>$this->group = "(".$this->alpha."(".$this->alpha."|".$this->digit."|[-.+_])*)"; <BR>$this->grouppart = "(|".$this->group."|".$this->article.")"; <BR>$this->newsurl = "([nN][eE][wW][sS]:".$this->grouppart.")"; <BR><BR><BR><BR>$this->nntpurl = "([nN][nN][tT][pP]://".$this->hostport."/".$this->group."(/".$this->digits.")?)"; <BR><BR><BR><BR>$this->telneturl = "([tT][eE][lL][nN][eE][tT]://".$this->login."/?)"; <BR><BR><BR><BR>$this->wpath = "(".$this->uchar."*)"; <BR>$this->wtype = "(".$this->uchar."*)"; <BR>$this->database = "(".$this->uchar."*)"; <BR>$this->waisdoc = "([wW][aA][iI][sS]://".$this->hostport."/".$this->database."/".$this->wtype."/".$this->wpath.")"; <BR>$this->waisindex = "([wW][aA][iI][sS]://".$this->hostport."/".$this->database."[?]".$this->search.")"; <BR>$this->waisdatabase = "([wW][aA][iI][sS]://".$this->hostport."/".$this->database.")"; <BR>$this->waisurl = "(".$this->waisdatabase."|".$this->waisindex."|".$this->waisdoc.")"; <BR>} <BR>} <BR><BR><BR><BR>/*测试 <BR>$urlcheck = new urlcheck(); <BR><BR><BR><BR>$url = array( <BR>"ftp://localhost/test/a", <BR>"file://localhost/test/a", <BR>"http://localhost/test/a", <BR>"https://localhost/test/a", <BR>"gopher://localhost/test/a", <BR>"news:comp.os.linux", <BR>"nntp://localhost/test/12", <BR>"telnet://localhost/", <BR>"wais://localhost/db/type/path", <BR>"error" <BR>); <BR>$count = count($url); <BR>for($i=0;$i<$count;$i++){ <BR>if($urlcheck->check($url[$i])) echo $url[$i]." ==> 合法 <BR>"; <BR>else echo $url[$i]." ==> 非法 <BR>"; <BR>} <BR><BR><BR><BR>$waisurl = array( <BR>"wais://localhost/", <BR>"wais://localhost/db", <BR>"wais://localhost/db?a=b&c=d", <BR>"wais://localhost/db/type/path", <BR>"WAIS://localhost/db", <BR>"error", <BR>"\\", <BR>"wai://localhost/db", <BR>"wais://localhost/db/", <BR>"wais://localhost/db/type/path/ext" <BR>); <BR>echo " <BR>".$urlcheck->waisurl." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($waisurl); <BR>for($i=0;$i<$count;$i++){ <BR>if(ereg("^".$urlcheck->waisurl."$",$waisurl[$i])) echo $waisurl[$i]." ==> 合法 <BR>"; <BR>else echo $waisurl[$i]." ==> 非法 <BR>"; <BR>} <BR><BR><BR><BR>$telneturl = array( <BR>"telnet://localhost", <BR>"telnet://localhost/", <BR>"TELNET://localhost", <BR>"telnet://guest:guest@localhost", <BR>"error", <BR>"\\", <BR>"telne://localhost" <BR>); <BR>echo " <BR>".$urlcheck->telneturl." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($telneturl); <BR>for($i=0;$i<$count;$i++){ <BR>if(ereg("^".$urlcheck->telneturl."$",$telneturl[$i])) echo $telneturl[$i]." ==> 合法 <BR>"; <BR>else echo $telneturl[$i]." ==> 非法 <BR>"; <BR>} <BR><BR><BR><BR>$nntpurl = array( <BR>"nntp://localhost/php/12", <BR>"NNTP://localhost/php/12", <BR>"nntp://localhost:119/php/12", <BR>"nntp://localhost/php", <BR>"error", <BR>"\\", <BR>"nnt://localhost/php", <BR>"nntp://localhost/php/" <BR>); <BR>echo " <BR>".$urlcheck->nntpurl." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($nntpurl); <BR>for($i=0;$i<$count;$i++){ <BR>if(ereg("^".$urlcheck->nntpurl."$",$nntpurl[$i])) echo $nntpurl[$i]." ==> 合法 <BR>"; <BR>else echo $nntpurl[$i]." ==> 非法 <BR>"; <BR>} <BR><BR><BR><BR>$newsurl = array( <BR>"news:123@localhost", <BR>"NEWS:123@localhost", <BR>"news:comp.os.linux", <BR>"news:*", <BR>"error", <BR>"\\", <BR>"news:http://www.phpchina.com/", <BR>"new:comp.os.linux", <BR>"news:" <BR>); <BR>echo " <BR>".$urlcheck->newsurl." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($newsurl); <BR>for($i=0;$i<$count;$i++){ <BR>if(ereg("^".$urlcheck->newsurl."$",$newsurl[$i])) echo $newsurl[$i]." ==> 合法 <BR>"; <BR>else echo $newsurl[$i]." ==> 非法 <BR>"; <BR>} <BR><BR><BR><BR>$gopherurl = array( <BR>"gopher://phpchina.com", <BR>"gopher://phpchina.com/", <BR>"gopher://phpchina.com/atest%09search%09string", <BR>"GOPHER://phpcina.com/", <BR>"error", <BR>"\\", <BR>"goph://phpchina.com" <BR>); <BR>echo " <BR>".$urlcheck->gopherurl." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($gopherurl); <BR>for($i=0;$i<$count;$i++){ <BR>if(ereg("^".$urlcheck->gopherurl."$",$gopherurl[$i])) echo $gopherurl[$i]." ==> 合法 <BR>"; <BR>else echo $gopherurl[$i]." ==> 非法 <BR>"; <BR>} <BR><BR><BR><BR>$httpurl = array( <BR>"http://www.phpchina.com", <BR>"http://www.phpchina.com/", <BR>"http://www.phpchina.com/default.php", <BR>"https://www.phpchina.com/", <BR>"HTTPS://www.phpchina.com/", <BR>"http://www.phpchina.com/?a=b&c=d", <BR>"error", <BR>"\\", <BR>"htt://www.phpchina.com/" <BR>); <BR>echo " <BR>".$urlcheck->httpurl." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($httpurl); <BR>for($i=0;$i<$count;$i++){ <BR>if(ereg("^".$urlcheck->httpurl."$",$httpurl[$i])) echo $httpurl[$i]." ==> 合法 <BR>"; <BR>else echo $httpurl[$i]." ==> 非法 <BR>"; <BR>} <BR><BR><BR><BR>$fileurl = array( <BR>"file://localhost/", <BR>"FILE://localhost/tmp/", <BR>"file://ahost/test/", <BR>"error", <BR>"\\", <BR>"file://localhost" <BR>); <BR>echo " <BR>".$urlcheck->fileurl." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($fileurl); <BR>for($i=0;$i<$count;$i++){ <BR>if(ereg("^".$urlcheck->fileurl."$",$fileurl[$i])) echo $fileurl[$i]." ==> 合法 <BR>"; <BR>else echo $fileurl[$i]." ==> 非法 <BR>"; <BR>} <BR><BR><BR><BR>$ftpurl = array( <BR>"ftp://www.phpchina.com", <BR>"ftp://www.phpchina.com/", <BR>"ftp://www.phpchina.com/test", <BR>"ftp://www.phpchina.com/test/", <BR>"ftp://www.phpchina.com/test/abc/aa", <BR>"ftp://www.phpchina.com:21", <BR>"ftp://www.phpchina.com:21/", <BR>"ftp://guest@www.phpchina.com/", <BR>"ftp://@www.phpchina.com/", <BR>"ftp:// www.phpchina.com/", <BR>"ftp://guest www.phpchina.com/", <BR>"ftp://guest:guest@www.phpchina.com/", <BR>"ftp://guest:guest@www.phpchina.com:21", <BR>"Ftp://www.phpchina.com/", <BR>"ftp://www.phpchina.com/test;type=a", <BR>"ftp://www.phpchina.com/;type=a", <BR>"FTP://www.phpchina.com/;TYPE=A", <BR>"error", <BR>"\\", <BR>"ftp://", <BR>"www.phpchina.com", <BR>"ff://www.phpchina.com", <BR>"ftp://www.phpchina.com;type=a", <BR>"ftp://www.phpchina.com/;type=b" <BR>); <BR>echo " <BR>".$urlcheck->ftpurl." 测试... <BR>"; <BR>$count = count($ftpurl); <BR>for($i=0;$i<$count;$i++){ <BR>if(ereg("^".$urlcheck->ftpurl."$",$ftpurl[$i])) echo $ftpurl[$i]." ==> 合法 <BR>"; <BR>else echo $ftpurl[$i]." ==> 非法 <BR>"; <BR>} <BR><BR><BR><BR>$login = array( <BR>"www.chinaasp.com", <BR>"www.phpchina.com", <BR>"202.101.17.181", <BR>"www.phpchina.com:80", <BR>"202.101.17.181:80", <BR>"guest@www.phpchina.com:80", <BR>"guest@202.101.17.181:80", <BR>"guest:guest@www.phpchina.com:80", <BR>"guest:guest@202.101.17.181:80", <BR>"guest www.phpchina.com:80", <BR>"guest 202.101.17.181:80", <BR>"@www.phpchina.com:80", <BR>"@202.101.17.181:80", <BR>"error", <BR>"\\", <BR>"@", <BR>"guest@" <BR>); <BR>echo " <BR>".$urlcheck->login." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($login); <BR>for($i=0;$i<$count;$i++){ <BR>if(ereg("^".$urlcheck->login."$",$login[$i])) echo $login[$i]." ==> 合法 <BR>"; <BR>else echo $login[$i]." ==> 非法 <BR>"; <BR>} <BR><BR><BR><BR>$hostport = array( <BR>"www.chinaasp.com", <BR>"www.phpchina.com", <BR>"202.101.17.181", <BR>"www.phpchina.com:80", <BR>"202.101.17.181:80", <BR>"error", <BR>"\\", <BR>"www.phpchina.com:abc" <BR>); <BR>echo " <BR>".$urlcheck->hostport." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($hostport); <BR>for($i=0;$i<$count;$i++){ <BR>if(ereg("^".$urlcheck->hostport."$",$hostport[$i])) echo $hostport[$i]." ==> 合法 <BR>"; <BR>else echo $hostport[$i]." ==> 非法 <BR>"; <BR>} <BR><BR><BR><BR>$host = array( <BR>"www.chinaasp.com", <BR>"www.phpchina.com", <BR>"202.101.17.181", <BR>"error", <BR>"\\", <BR>"www.phpchina.com:80" <BR>); <BR>echo " <BR>".$urlcheck->host." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($host); <BR>for($i=0;$i<$count;$i++){ <BR>if(ereg("^".$urlcheck->host."$",$host[$i])) echo $host[$i]." ==> 合法 <BR>"; <BR>else echo $host[$i]." ==> 非法 <BR>"; <BR>} <BR><BR><BR><BR>$hostname = array( <BR>"www.chinaasp.com", <BR>"www.phpchina.com", <BR>"1.a", <BR>"1.abc", <BR>"1.a-c", <BR>"1.ab-c", <BR>"1.a8-9", <BR>"1-2.a", <BR>"1-2.abc", <BR>"1-2.a-c", <BR>"1-2.ab-c", <BR>"1-2.a8-9", <BR>"1-2.1-2.a", <BR>"1-2.1-2.abc", <BR>"1-2.1-2.a-c", <BR>"1-2.1-2.ab-c", <BR>"1-2.1-2.a8-9", <BR>"a", <BR>"e", <BR>"z", <BR>"A", <BR>"E", <BR>"Z", <BR>"abc", <BR>"a-c", <BR>"ab-c", <BR>"ab-9", <BR>"a8-9", <BR>"error", <BR>"\\", <BR>"1", <BR>"123", <BR>"1a3", <BR>"1-3", <BR>"abc*", <BR>"!safa" <BR>); <BR>echo " <BR>".$urlcheck->hostname." 测试 <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($hostname); <BR>for($i=0;$i<$count;$i++){ <BR>if(ereg("^".$urlcheck->hostname."$",$hostname[$i])) echo $hostname[$i]." ==> 合法 <BR>"; <BR>else echo $hostname[$i]." ==> 非法 <BR>"; <BR>} <BR><BR><BR><BR>$hostnumber = array( <BR>"202.101.17.181", <BR>"127.0.0.1", <BR>"error", <BR>"\\", <BR>"202.101.17.", <BR>"202.101..", <BR>"202...", <BR>"....", <BR>"ab.cd.ef.gh" <BR>); <BR>echo " <BR>".$urlcheck->hostnumber." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($hostnumber); <BR>for($i=0;$i<$count;$i++){ <BR>if(ereg("^".$urlcheck->hostnumber."$",$hostnumber[$i])) echo $hostnumber[$i]." ==> 合法 <BR>"; <BR>else echo $hostnumber[$i]." ==> 非法 <BR>"; <BR>} <BR><BR><BR><BR>$lowalpha = array( <BR>"a", <BR>"e", <BR>"z", <BR>"error", <BR>"\\", <BR>"A", <BR>"0", <BR>"ae" <BR>); <BR>echo " <BR>".$urlcheck->lowalpha." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($lowalpha); <BR>for($i=0;$i<$count;$i++){ <BR>if(ereg("^".$urlcheck->lowalpha."$",$lowalpha[$i])) echo $lowalpha[$i]." ==> 合法 <BR>"; <BR>else echo $lowalpha[$i]." ==> 非法 <BR>"; <BR>} <BR><BR><BR><BR>$hialpha = array( <BR>"A", <BR>"E", <BR>"Z", <BR>"error", <BR>"\\", <BR>"a", <BR>"2", <BR>"AB" <BR>); <BR>echo " <BR>".$urlcheck->hialpha." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($hialpha); <BR>for($i=0;$i<$count;$i++){ <BR>if(ereg("^".$urlcheck->hialpha."$",$hialpha[$i])) echo $hialpha[$i]." ==> 合法 <BR>"; <BR>else echo $hialpha[$i]." ==> 非法 <BR>"; <BR>} <BR><BR><BR><BR>$alpha = array( <BR>"a", <BR>"e", <BR>"z", <BR>"A", <BR>"E", <BR>"Z", <BR>"error", <BR>"\\", <BR>"ab", <BR>"AB", <BR>"1", <BR>"a1" <BR>); <BR>echo " <BR>".$urlcheck->alpha." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($alpha); <BR>for($i=0;$i<$count;$i++){ <BR>if(ereg("^".$urlcheck->alpha."$",$alpha[$i])) echo $alpha[$i]." ==> 合法 <BR>"; <BR>else echo $alpha[$i]." ==> 非法 <BR>"; <BR>} <BR><BR><BR><BR>$digit = array( <BR>"0", <BR>"4", <BR>"9", <BR>"error", <BR>"\\", <BR>"12", <BR>"ab" <BR>); <BR>echo " <BR>".$urlcheck->digit." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($digit); <BR>for($i=0;$i<$count;$i++){ <BR>if(ereg("^".$urlcheck->digit."$",$digit[$i])) echo $digit[$i]." ==> 合法 <BR>"; <BR>else echo $digit[$i]." ==> 非法 <BR>"; <BR>} <BR><BR><BR><BR>$hex = array( <BR>"0", <BR>"4", <BR>"9", <BR>"a", <BR>"e", <BR>"f", <BR>"A", <BR>"E", <BR>"F", <BR>"error", <BR>"\\", <BR>"01", <BR>"G", <BR>"g", <BR>"ab" <BR>); <BR>echo " <BR>".$urlcheck->hex." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($hex); <BR>for($i=0;$i<$count;$i++){ <BR>if(ereg("^".$urlcheck->hex."$",$hex[$i])) echo $hex[$i]." ==> 合法 <BR>"; <BR>else echo $hex[$i]." ==> 非法 <BR>"; <BR>} <BR><BR><BR><BR>$digits = array( <BR>"0", <BR>"4", <BR>"9", <BR>"12", <BR>"124", <BR>"error", <BR>"\\", <BR>"", <BR>"a", <BR>"afasdf" <BR>); <BR>echo " <BR>".$urlcheck->digits." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($digits); <BR>for($i=0;$i<$count;$i++){ <BR>if(ereg("^".$urlcheck->digits."$",$digits[$i])) echo $digits[$i]." ==> 合法 <BR>"; <BR>else echo $digits[$i]." ==> 非法 <BR>"; <BR>} <BR><BR><BR><BR>$xchar = array( <BR>"a", <BR>"e", <BR>"z", <BR>"A", <BR>"E", <BR>"Z", <BR>"0", <BR>"5", <BR>"9", <BR>"$", <BR>".", <BR>"+", <BR>"_", <BR>"-", <BR>"*", <BR>"(", <BR>")", <BR>"\"", <BR>"!", <BR>",", <BR>"?", <BR>";", <BR>"/", <BR>":", <BR>"@", <BR>"&", <BR>"=", <BR>"%02", <BR>"%a0", <BR>"%af", <BR>"error", <BR>"\\", <BR>"ae", <BR>"AE", <BR>"$-", <BR>"*)", <BR>"?/", <BR>"%0z", <BR>"%az", <BR>"%abc", <BR>"%012" <BR>); <BR>echo " <BR>".$urlcheck->xchar." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($xchar); <BR>for($i=0;$i<$count;$i++){ <BR>if(ereg("^".$urlcheck->xchar."$",$xchar[$i])) echo $xchar[$i]." ==> 合法 <BR>"; <BR>else echo $xchar[$i]." ==> 非法 <BR>"; <BR>} <BR><BR><BR><BR>$uchar = array( <BR>"a", <BR>"e", <BR>"z", <BR>"A", <BR>"E", <BR>"Z", <BR>"0", <BR>"5", <BR>"9", <BR>"$", <BR>".", <BR>"+", <BR>"_", <BR>"-", <BR>"*", <BR>"(", <BR>")", <BR>"\"", <BR>"!", <BR>"%02", <BR>"%a0", <BR>"%Af", <BR>"error", <BR>"\\", <BR>"ab", <BR>"Aa", <BR>"01", <BR>"$+", <BR>"(!", <BR>"%124", <BR>"%abc", <BR>"%az" <BR>); <BR>echo " <BR>".$urlcheck->uchar." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($uchar); <BR>for($i=0;$i<$count;$i++){ <BR>if(ereg("^".$urlcheck->uchar."$",$uchar[$i])) echo $uchar[$i]." ==> 合法 <BR>"; <BR>else echo $uchar[$i]." ==> 非法 <BR>"; <BR>} <BR><BR><BR><BR>$unreserved = array( <BR>"a", <BR>"e", <BR>"z", <BR>"A", <BR>"E", <BR>"Z", <BR>"0", <BR>"5", <BR>"9", <BR>"$", <BR>".", <BR>"+", <BR>"_", <BR>"-", <BR>"*", <BR>"(", <BR>")", <BR>"\"", <BR>"!", <BR>",", <BR>"error", <BR>"\\", <BR>"ab", <BR>"Ab", <BR>"01", <BR>"$.", <BR>"*(" <BR>); <BR>echo " <BR>".$urlcheck->unreserved." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($unreserved); <BR>for($i=0;$i<$count;$i++){ <BR>if(ereg("^".$urlcheck->unreserved."$",$unreserved[$i])) echo $unreserved[$i]." ==> 合法 <BR>"; <BR>else echo $unreserved[$i]." ==> 非法 <BR>"; <BR>} <BR><BR><BR><BR>$reserved = array( <BR>";", <BR>"/", <BR>"?", <BR>":", <BR>"@", <BR>"&", <BR>"=", <BR>"error", <BR>"\\", <BR>"a", <BR>"==" <BR>); <BR>echo " <BR>".$urlcheck->reserved." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($reserved); <BR>for($i=0;$i<$count;$i++){ <BR>if(ereg("^".$urlcheck->reserved."$",$reserved[$i])) echo $reserved[$i]." ==> 合法 <BR>"; <BR>else echo $reserved[$i]." ==> 非法 <BR>"; <BR>} <BR><BR><BR><BR>$punctuation = array( <BR>"<", <BR>">", <BR>"#", <BR>"%", <BR>""", <BR>"error", <BR>"\\", <BR>"<<", <BR>">>", <BR>"a" <BR>); <BR>echo " <BR>".$urlcheck->punctuation." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($punctuation); <BR>for($i=0;$i<$count;$i++){ <BR>if(ereg("^".$urlcheck->punctuation."$",$punctuation[$i])) echo $punctuation[$i]." ==> 合法 <BR>"; <BR>else echo $punctuation[$i]." ==> 非法 <BR>"; <BR>} <BR><BR><BR><BR>$national = array( <BR>"{", <BR>"}", <BR>"|", <BR>"\\", <BR>"^", <BR>"~", <BR>"[", <BR>"]", <BR>"`", <BR>"error", <BR>"``", <BR>"^^" <BR>); <BR>echo " <BR>".$urlcheck->national." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($national); <BR>for($i=0;$i<$count;$i++){ <BR>if(ereg("^".$urlcheck->national."$",$national[$i])) echo $national[$i]." ==> 合法 <BR>"; <BR>else echo $national[$i]." ==> 非法 <BR>"; <BR>} <BR><BR><BR><BR>$safe = array( <BR>"$", <BR>"-", <BR>"_", <BR>".", <BR>"+", <BR>"error", <BR>"\\", <BR>"1", <BR>"$$" <BR>); <BR>echo " <BR>".$urlcheck->safe." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($safe); <BR>for($i=0;$i<$count;$i++){ <BR>if(ereg("^".$urlcheck->safe."$",$safe[$i])) echo $safe[$i]." ==> 合法 <BR>"; <BR>else echo $safe[$i]." ==> 非法 <BR>"; <BR>} <BR><BR><BR><BR>$extra = array( <BR>"!", <BR>"*", <BR>"\"", <BR>"(", <BR>")", <BR>",", <BR>"error", <BR>"\\", <BR>"a" <BR>); <BR>echo " <BR>".$urlcheck->extra."测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($extra); <BR>for($i=0;$i<$count;$i++){ <BR>if(ereg("^".$urlcheck->extra."$",$extra[$i])) echo $extra[$i]." ==> 合法 <BR>"; <BR>else echo $extra[$i]." ==> 非法 <BR>"; <BR>} <BR>$escape = array( <BR>"%12", <BR>"%1a", <BR>"%A1", <BR>"error", <BR>"\\", <BR>"%az", <BR>"%123", <BR>"%abc" <BR>); <BR>echo " <BR>".$urlcheck->escape." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($escape); <BR>for($i=0;$i<$count;$i++){ <BR>if(ereg("^".$urlcheck->escape."$",$escape[$i])) echo $escape[$i]." ==> 合法 <BR>"; <BR>else echo $escape[$i]." ==> 非法 <BR>"; <BR>} <BR>*/ <BR>?> <br><br> |
|