摘要:functionmatchip($q){preg_match('((25[0-5])|(2[0-4]d)|(1dd)|([1-9]d)|d)(.((25[0-5])|(2[0-4]d)|(1dd)|([1-9]d)|d)){3}',$q,$matches);return$matches[...
轉(zhuǎn)載請(qǐng)注明來(lái)源:php 判斷IP是否合法正則表達(dá)式代碼
轉(zhuǎn)載請(qǐng)注明來(lái)源:php 判斷IP是否合法正則表達(dá)式代碼
- function matchip($q){
- preg_match('/((25[0-5])|(2[0-4]d)|(1dd)|([1-9]d)|d)(.((25[0-5])|(2[0-4]d)|(1dd)|([1-9]d)|d)){3}/', $q, $matches);
- return $matches[0];
- }
- $ipaddress = '201.103.2.2';
- $iperror ='262.3.6.6';
- $iptest = matchip( $ipaddress );
- //當(dāng)我們給matchip 的值為$ipaddress輸出為201.103.2.2
- //當(dāng)我們給matchip的函數(shù)值為$iperror時(shí),輸出值為 62.3.6.6
- 代碼如下 復(fù)制代碼
- if( $iptest )
- {
- echo $iptest;
- }
- else
- {
- echo 'phpfensi.com提示:你輸?shù)牡膇p地址有問(wèn)題';
- }
哈爾濱品用軟件有限公司致力于為哈爾濱的中小企業(yè)制作大氣、美觀的優(yōu)秀網(wǎng)站,并且能夠搭建符合百度排名規(guī)范的網(wǎng)站基底,使您的網(wǎng)站無(wú)需額外費(fèi)用,即可穩(wěn)步提升排名至首頁(yè)。歡迎體驗(yàn)最佳的哈爾濱網(wǎng)站建設(shè)。
