设为首页收藏本站language 语言切换
查看: 1071|回复: 0
收起左侧

URL地址合法性检查

[复制链接]
发表于 2010-2-24 13:33:39 | 显示全部楼层 |阅读模式
<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(//协议名(注意在这里必须写成小写) =&gt; 对应的正则表达式 <BR>"ftp" =&gt; "$this-&gt;ftpurl", <BR>"file" =&gt; "$this-&gt;fileurl", <BR>"http" =&gt; "$this-&gt;httpurl", <BR>"https" =&gt; "$this-&gt;httpurl", <BR>"gopher" =&gt; "$this-&gt;gopherurl", <BR>"news" =&gt; "$this-&gt;newsurl", <BR>"nntp" =&gt; "$this-&gt;nntpurl", <BR>"telnet" =&gt; "$this-&gt;telneturl", <BR>"wais" =&gt; "$this-&gt;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&lt;1) return false; <BR>$prot = substr($url,0,$pos); <BR>if(!isset($this-&gt;regex[$prot])) return false; <BR>eval("$regex = ".$this-&gt;regex[$prot].";"); <BR>return ereg("^".$regex."$",$url); <BR>} <BR><BR><BR><BR>function urlcheck(){ <BR>$this-&gt;lowalpha = "[a-z]"; <BR>$this-&gt;hialpha = "[A-Z]"; <BR>$this-&gt;alpha = "(".$this-&gt;lowalpha."|".$this-&gt;hialpha.")"; <BR>$this-&gt;digit = "[0-9]"; <BR>$this-&gt;safe = "[$.+_-]"; <BR>$this-&gt;extra = "[*()\"!,]"; <BR>$this-&gt;national = "([{}|\^~`]|\\[|\\])"; <BR>$this-&gt;punctuation = "[&lt;&gt;#%"]"; <BR>$this-&gt;reserved = "[?;/&amp;=]"; <BR>$this-&gt;hex = "(".$this-&gt;digit."|[a-fA-F])"; <BR>$this-&gt;escape = "(%".$this-&gt;hex."{2})"; <BR>$this-&gt;unreserved = "(".$this-&gt;alpha."|".$this-&gt;digit."|".$this-&gt;safe."|".$this-&gt;extra.")"; <BR>$this-&gt;uchar = "(".$this-&gt;unreserved."|".$this-&gt;escape.")"; <BR>$this-&gt;xchar = "(".$this-&gt;unreserved."|".$this-&gt;reserved."|".$this-&gt;escape.")"; <BR>$this-&gt;digits = "(".$this-&gt;digit."+)"; <BR><BR><BR><BR>$this-&gt;urlpath = "(".$this-&gt;xchar."*)"; <BR>$this-&gt;password = "((".$this-&gt;uchar."|[?;&amp;=]".")*)"; <BR>$this-&gt;user = "((".$this-&gt;uchar."|[?;&amp;=]".")*)"; <BR>$this-&gt;port = $this-&gt;digits; <BR>$this-&gt;hostnumber = "(".$this-&gt;digits.".".$this-&gt;digits.".".$this-&gt;digits.".".$this-&gt;digits.")"; <BR>$this-&gt;alphadigit = "(".$this-&gt;alpha."|".$this-&gt;digit.")"; <BR>$this-&gt;toplabel = "(".$this-&gt;alpha."|(".$this-&gt;alpha."(".$this-&gt;alphadigit."|-)*".$this-&gt;alphadigit."))"; <BR>$this-&gt;domainlabel = "(".$this-&gt;alphadigit."|(".$this-&gt;alphadigit."(".$this-&gt;alphadigit."|-)*".$this-&gt;alphadigit."))"; <BR>$this-&gt;hostname = "((".$this-&gt;domainlabel."\\.)*".$this-&gt;toplabel.")"; <BR>$this-&gt;host = "(".$this-&gt;hostname."|".$this-&gt;hostnumber.")"; <BR>$this-&gt;hostport = "(".$this-&gt;host."(:".$this-&gt;port.")?)"; <BR>$this-&gt;login = "((".$this-&gt;user."(:".$this-&gt;password.")?@)?".$this-&gt;hostport.")"; <BR><BR><BR><BR>$this-&gt;ftptype = "[aidAID]"; <BR>$this-&gt;fsegment = "((".$this-&gt;uchar."|[?&amp;=])*)"; <BR>$this-&gt;fpath = "(".$this-&gt;fsegment."(/".$this-&gt;fsegment.")*)"; <BR>$this-&gt;ftpurl = "([fF][tT][pP]://".$this-&gt;login."(/".$this-&gt;fpath."(;[tT][yY][pP][eE]=".$this-&gt;ftptype.")?)?)"; <BR><BR><BR><BR>$this-&gt;fileurl = "([fF][iI][lL][eE]://(".$this-&gt;host."|[lL][oO][cC][aA][lL][hH][oO][sS][tT])?/".$this-&gt;fpath.")"; <BR><BR><BR><BR>$this-&gt;search = "((".$this-&gt;uchar."|[;&amp;=])*)"; <BR>$this-&gt;hsegment = "((".$this-&gt;uchar."|[;&amp;=])*)"; <BR>$this-&gt;hpath = "(".$this-&gt;hsegment."(/".$this-&gt;hsegment.")*)"; <BR>$this-&gt;httpurl = "([hH][tT][tT][pP][sS]?://".$this-&gt;hostport."(/".$this-&gt;hpath."([?]".$this-&gt;search.")?)?)"; <BR><BR><BR><BR>$this-&gt;gopher_string = "(".$this-&gt;xchar."*)"; <BR>$this-&gt;selector = "(".$this-&gt;xchar."*)"; <BR>$this-&gt;gtype = $this-&gt;xchar; <BR>$this-&gt;gopherurl = "([gG][oO][pP][hH][eE][rR]://".$this-&gt;hostport."(/(".$this-&gt;gtype."(".$this-&gt;selector."(%09".$this-&gt;search."(%09".$this-&gt;gopher_string.")?)?)?)?)?)"; <BR><BR><BR><BR>$this-&gt;article = "((".$this-&gt;uchar."|[;/?:&amp;=])+@".$this-&gt;host.")"; <BR>$this-&gt;group = "(".$this-&gt;alpha."(".$this-&gt;alpha."|".$this-&gt;digit."|[-.+_])*)"; <BR>$this-&gt;grouppart = "(
  • |".$this-&gt;group."|".$this-&gt;article.")"; <BR>$this-&gt;newsurl = "([nN][eE][wW][sS]:".$this-&gt;grouppart.")"; <BR><BR><BR><BR>$this-&gt;nntpurl = "([nN][nN][tT][pP]://".$this-&gt;hostport."/".$this-&gt;group."(/".$this-&gt;digits.")?)"; <BR><BR><BR><BR>$this-&gt;telneturl = "([tT][eE][lL][nN][eE][tT]://".$this-&gt;login."/?)"; <BR><BR><BR><BR>$this-&gt;wpath = "(".$this-&gt;uchar."*)"; <BR>$this-&gt;wtype = "(".$this-&gt;uchar."*)"; <BR>$this-&gt;database = "(".$this-&gt;uchar."*)"; <BR>$this-&gt;waisdoc = "([wW][aA][iI][sS]://".$this-&gt;hostport."/".$this-&gt;database."/".$this-&gt;wtype."/".$this-&gt;wpath.")"; <BR>$this-&gt;waisindex = "([wW][aA][iI][sS]://".$this-&gt;hostport."/".$this-&gt;database."[?]".$this-&gt;search.")"; <BR>$this-&gt;waisdatabase = "([wW][aA][iI][sS]://".$this-&gt;hostport."/".$this-&gt;database.")"; <BR>$this-&gt;waisurl = "(".$this-&gt;waisdatabase."|".$this-&gt;waisindex."|".$this-&gt;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&lt;$count;$i++){ <BR>if($urlcheck-&gt;check($url[$i])) echo $url[$i]." ==&gt; 合法 <BR>"; <BR>else echo $url[$i]." ==&gt; 非法 <BR>"; <BR>} <BR><BR><BR><BR>$waisurl = array( <BR>"wais://localhost/", <BR>"wais://localhost/db", <BR>"wais://localhost/db?a=b&amp;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-&gt;waisurl." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($waisurl); <BR>for($i=0;$i&lt;$count;$i++){ <BR>if(ereg("^".$urlcheck-&gt;waisurl."$",$waisurl[$i])) echo $waisurl[$i]." ==&gt; 合法 <BR>"; <BR>else echo $waisurl[$i]." ==&gt; 非法 <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-&gt;telneturl." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($telneturl); <BR>for($i=0;$i&lt;$count;$i++){ <BR>if(ereg("^".$urlcheck-&gt;telneturl."$",$telneturl[$i])) echo $telneturl[$i]." ==&gt; 合法 <BR>"; <BR>else echo $telneturl[$i]." ==&gt; 非法 <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-&gt;nntpurl." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($nntpurl); <BR>for($i=0;$i&lt;$count;$i++){ <BR>if(ereg("^".$urlcheck-&gt;nntpurl."$",$nntpurl[$i])) echo $nntpurl[$i]." ==&gt; 合法 <BR>"; <BR>else echo $nntpurl[$i]." ==&gt; 非法 <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-&gt;newsurl." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($newsurl); <BR>for($i=0;$i&lt;$count;$i++){ <BR>if(ereg("^".$urlcheck-&gt;newsurl."$",$newsurl[$i])) echo $newsurl[$i]." ==&gt; 合法 <BR>"; <BR>else echo $newsurl[$i]." ==&gt; 非法 <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-&gt;gopherurl." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($gopherurl); <BR>for($i=0;$i&lt;$count;$i++){ <BR>if(ereg("^".$urlcheck-&gt;gopherurl."$",$gopherurl[$i])) echo $gopherurl[$i]." ==&gt; 合法 <BR>"; <BR>else echo $gopherurl[$i]." ==&gt; 非法 <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&amp;c=d", <BR>"error", <BR>"\\", <BR>"htt://www.phpchina.com/" <BR>); <BR>echo " <BR>".$urlcheck-&gt;httpurl." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($httpurl); <BR>for($i=0;$i&lt;$count;$i++){ <BR>if(ereg("^".$urlcheck-&gt;httpurl."$",$httpurl[$i])) echo $httpurl[$i]." ==&gt; 合法 <BR>"; <BR>else echo $httpurl[$i]." ==&gt; 非法 <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-&gt;fileurl." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($fileurl); <BR>for($i=0;$i&lt;$count;$i++){ <BR>if(ereg("^".$urlcheck-&gt;fileurl."$",$fileurl[$i])) echo $fileurl[$i]." ==&gt; 合法 <BR>"; <BR>else echo $fileurl[$i]." ==&gt; 非法 <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://guestwww.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-&gt;ftpurl." 测试... <BR>"; <BR>$count = count($ftpurl); <BR>for($i=0;$i&lt;$count;$i++){ <BR>if(ereg("^".$urlcheck-&gt;ftpurl."$",$ftpurl[$i])) echo $ftpurl[$i]." ==&gt; 合法 <BR>"; <BR>else echo $ftpurl[$i]." ==&gt; 非法 <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>"guestwww.phpchina.com:80", <BR>"guest202.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-&gt;login." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($login); <BR>for($i=0;$i&lt;$count;$i++){ <BR>if(ereg("^".$urlcheck-&gt;login."$",$login[$i])) echo $login[$i]." ==&gt; 合法 <BR>"; <BR>else echo $login[$i]." ==&gt; 非法 <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-&gt;hostport." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($hostport); <BR>for($i=0;$i&lt;$count;$i++){ <BR>if(ereg("^".$urlcheck-&gt;hostport."$",$hostport[$i])) echo $hostport[$i]." ==&gt; 合法 <BR>"; <BR>else echo $hostport[$i]." ==&gt; 非法 <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-&gt;host." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($host); <BR>for($i=0;$i&lt;$count;$i++){ <BR>if(ereg("^".$urlcheck-&gt;host."$",$host[$i])) echo $host[$i]." ==&gt; 合法 <BR>"; <BR>else echo $host[$i]." ==&gt; 非法 <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-&gt;hostname." 测试 <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($hostname); <BR>for($i=0;$i&lt;$count;$i++){ <BR>if(ereg("^".$urlcheck-&gt;hostname."$",$hostname[$i])) echo $hostname[$i]." ==&gt; 合法 <BR>"; <BR>else echo $hostname[$i]." ==&gt; 非法 <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-&gt;hostnumber." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($hostnumber); <BR>for($i=0;$i&lt;$count;$i++){ <BR>if(ereg("^".$urlcheck-&gt;hostnumber."$",$hostnumber[$i])) echo $hostnumber[$i]." ==&gt; 合法 <BR>"; <BR>else echo $hostnumber[$i]." ==&gt; 非法 <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-&gt;lowalpha." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($lowalpha); <BR>for($i=0;$i&lt;$count;$i++){ <BR>if(ereg("^".$urlcheck-&gt;lowalpha."$",$lowalpha[$i])) echo $lowalpha[$i]." ==&gt; 合法 <BR>"; <BR>else echo $lowalpha[$i]." ==&gt; 非法 <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-&gt;hialpha." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($hialpha); <BR>for($i=0;$i&lt;$count;$i++){ <BR>if(ereg("^".$urlcheck-&gt;hialpha."$",$hialpha[$i])) echo $hialpha[$i]." ==&gt; 合法 <BR>"; <BR>else echo $hialpha[$i]." ==&gt; 非法 <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-&gt;alpha." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($alpha); <BR>for($i=0;$i&lt;$count;$i++){ <BR>if(ereg("^".$urlcheck-&gt;alpha."$",$alpha[$i])) echo $alpha[$i]." ==&gt; 合法 <BR>"; <BR>else echo $alpha[$i]." ==&gt; 非法 <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-&gt;digit." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($digit); <BR>for($i=0;$i&lt;$count;$i++){ <BR>if(ereg("^".$urlcheck-&gt;digit."$",$digit[$i])) echo $digit[$i]." ==&gt; 合法 <BR>"; <BR>else echo $digit[$i]." ==&gt; 非法 <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-&gt;hex." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($hex); <BR>for($i=0;$i&lt;$count;$i++){ <BR>if(ereg("^".$urlcheck-&gt;hex."$",$hex[$i])) echo $hex[$i]." ==&gt; 合法 <BR>"; <BR>else echo $hex[$i]." ==&gt; 非法 <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-&gt;digits." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($digits); <BR>for($i=0;$i&lt;$count;$i++){ <BR>if(ereg("^".$urlcheck-&gt;digits."$",$digits[$i])) echo $digits[$i]." ==&gt; 合法 <BR>"; <BR>else echo $digits[$i]." ==&gt; 非法 <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>"&amp;", <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-&gt;xchar." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($xchar); <BR>for($i=0;$i&lt;$count;$i++){ <BR>if(ereg("^".$urlcheck-&gt;xchar."$",$xchar[$i])) echo $xchar[$i]." ==&gt; 合法 <BR>"; <BR>else echo $xchar[$i]." ==&gt; 非法 <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-&gt;uchar." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($uchar); <BR>for($i=0;$i&lt;$count;$i++){ <BR>if(ereg("^".$urlcheck-&gt;uchar."$",$uchar[$i])) echo $uchar[$i]." ==&gt; 合法 <BR>"; <BR>else echo $uchar[$i]." ==&gt; 非法 <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-&gt;unreserved." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($unreserved); <BR>for($i=0;$i&lt;$count;$i++){ <BR>if(ereg("^".$urlcheck-&gt;unreserved."$",$unreserved[$i])) echo $unreserved[$i]." ==&gt; 合法 <BR>"; <BR>else echo $unreserved[$i]." ==&gt; 非法 <BR>"; <BR>} <BR><BR><BR><BR>$reserved = array( <BR>";", <BR>"/", <BR>"?", <BR>":", <BR>"@", <BR>"&amp;", <BR>"=", <BR>"error", <BR>"\\", <BR>"a", <BR>"==" <BR>); <BR>echo " <BR>".$urlcheck-&gt;reserved." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($reserved); <BR>for($i=0;$i&lt;$count;$i++){ <BR>if(ereg("^".$urlcheck-&gt;reserved."$",$reserved[$i])) echo $reserved[$i]." ==&gt; 合法 <BR>"; <BR>else echo $reserved[$i]." ==&gt; 非法 <BR>"; <BR>} <BR><BR><BR><BR>$punctuation = array( <BR>"&lt;", <BR>"&gt;", <BR>"#", <BR>"%", <BR>""", <BR>"error", <BR>"\\", <BR>"&lt;&lt;", <BR>"&gt;&gt;", <BR>"a" <BR>); <BR>echo " <BR>".$urlcheck-&gt;punctuation." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($punctuation); <BR>for($i=0;$i&lt;$count;$i++){ <BR>if(ereg("^".$urlcheck-&gt;punctuation."$",$punctuation[$i])) echo $punctuation[$i]." ==&gt; 合法 <BR>"; <BR>else echo $punctuation[$i]." ==&gt; 非法 <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-&gt;national." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($national); <BR>for($i=0;$i&lt;$count;$i++){ <BR>if(ereg("^".$urlcheck-&gt;national."$",$national[$i])) echo $national[$i]." ==&gt; 合法 <BR>"; <BR>else echo $national[$i]." ==&gt; 非法 <BR>"; <BR>} <BR><BR><BR><BR>$safe = array( <BR>"$", <BR>"-", <BR>"_", <BR>".", <BR>"+", <BR>"error", <BR>"\\", <BR>"1", <BR>"$$" <BR>); <BR>echo " <BR>".$urlcheck-&gt;safe." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($safe); <BR>for($i=0;$i&lt;$count;$i++){ <BR>if(ereg("^".$urlcheck-&gt;safe."$",$safe[$i])) echo $safe[$i]." ==&gt; 合法 <BR>"; <BR>else echo $safe[$i]." ==&gt; 非法 <BR>"; <BR>} <BR><BR><BR><BR>$extra = array( <BR>"!", <BR>"*", <BR>"\"", <BR>"(", <BR>")", <BR>",", <BR>"error", <BR>"\\", <BR>"a" <BR>); <BR>echo " <BR>".$urlcheck-&gt;extra."测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($extra); <BR>for($i=0;$i&lt;$count;$i++){ <BR>if(ereg("^".$urlcheck-&gt;extra."$",$extra[$i])) echo $extra[$i]." ==&gt; 合法 <BR>"; <BR>else echo $extra[$i]." ==&gt; 非法 <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-&gt;escape." 测试... <BR>-------------------------------------------------------------------------------- <BR>"; <BR>$count = count($escape); <BR>for($i=0;$i&lt;$count;$i++){ <BR>if(ereg("^".$urlcheck-&gt;escape."$",$escape[$i])) echo $escape[$i]." ==&gt; 合法 <BR>"; <BR>else echo $escape[$i]." ==&gt; 非法 <BR>"; <BR>} <BR>*/ <BR>?&gt;                   <br><br>
  • 您需要登录后才可以回帖 登录 | 论坛注册

    本版积分规则

    QQ|Archiver|手机版|小黑屋|sitemap|鸿鹄论坛 ( 京ICP备14027439号 )  

    GMT+8, 2025-4-5 21:14 , Processed in 0.098527 second(s), 24 queries , Redis On.  

      Powered by Discuz!

      © 2001-2025 HH010.COM

    快速回复 返回顶部 返回列表