利用 preg_match(),我们可以完成字符串的规则匹配。如果找到一个匹配,preg_match() 函数返回 1,否则返回 0。还有一个可选的第三参数可以让你把匹配的部分存在一个数组中。在验证数据时这个功能可以变得非常有用。
实例代码如下:
- <?php
- // 模式定界符后面的 "i" 表示不区分大小写字母的搜索
- if (preg_match ("/php/i", "PHP is the web scripting language of choice.")) {
- print "A match was found.";
- } else {
- print "A match was not found.";
- }
- ?>
取得当前时间
实例代码如下:
- <?php
- //需要匹配的字符串。date函数返回当前时间。 "现在时刻:2012-04-20 07:31 am"
- $content = "现在时刻:".date("Y-m-d h:i a");
- //匹配日期和时间.
- if (preg_match ("/d{4}-d{2}-d{2} d{2}:d{2} [ap]m/", $content, $m))
- {
- echo "匹配的时间是:" .$m[0]. "n"; //"2012-04-20 07:31 am"
- }
- //分别取得日期和时间
- if (preg_match ("/([d-]{10}) ([d:]{5} [ap]m)/", $content, $m))
- {
- echo "当前日期是:" .$m[1]. "n"; //"2012-04-20"
- echo "当前时间是:" .$m[2]. "n"; //"07:31 am"
- }
- ?>
这个例子将验证出此 Email 地址为正确格式。现在让我们来看看这段正则表达式所代表的各种规则。
获取Google首页title
比如说要获取google首页的title内容,代码如下:
实例代码如下:
- <?php
- $str = file_get_contents('http://www.google.com');
- preg_match('/<title>(.*)</title>/', $str, $arr);
- echo $arr[1];
- ?>
从网址获取域名
实例代码如下:
- <?php
- preg_match("/^(http://)?([^/]+)/i", "http://www.111cn.net/index.html", $matches);
- $host = $matches[2]; // 从主机名中取得后面两段
- preg_match("/[^./]+.[^./]+$/", $host, $matches);
- echo "domain name is: {$matches[0]}n";
- ?>
preg_match($pattern,$string,$matcher)其中$pattern对应的就是/^(http://)?([^/]+)/i,$string 是http://www.php.net/index.html,$match是匹配到的结果。
如果提供了 matches,则其会被搜索的结果所填充。$matches[0] 将包含与整个模式匹配的文本,$matches[1] 将包
含与第一个捕获的括号中的子模式所匹配的文本,以此类推。
$matches[0] 将包含与整个模式匹配的文本。咱们用pring_r打印出来第一个$matches:
实例代码如下:
- Array (
- [0] => http://www.111cn.net
- [1] => http://
- [2] => http://www.phpfensi.com )
$matches[0] 将包含与整个模式匹配的文本,$matches[1] 将包含与第一个捕获的括号中的子模式所匹配的文本。在正则中,()代表模式:匹配 pattern 并获取这一匹配。所获取的匹配可以从产生的 Matches 集合得到,在VBScript 中使用 SubMatches 集合,在JScript 中则使用 $0…$9 属性。就是说数组中下标为1的值就是正则中/^(http://)?([^/]+)/i第一个()里的值!数组下标2的值以此类推。
波比源码 » php正则表达式之preg_match()用法
levofloxacin oral brand levaquin 250mg
avodart 0.5mg tablet ondansetron price zofran 8mg pills
aldactone 100mg brand oral finasteride 1mg purchase fluconazole pill
order ampicillin pill buy sulfamethoxazole generic cost erythromycin 250mg
order sildenafil 100mg online cheap bimatoprost ca methocarbamol 500mg for sale
sildenafil tablet estradiol 1mg generic order estradiol online
lamotrigine 50mg pill mebendazole drug retin over the counter
purchase tadalis generic generic avanafil buy diclofenac without prescription
indomethacin order online lamisil usa purchase amoxicillin online cheap
tadalafil 20mg oral Buy viagra in canada viagra for women
tadalafil 40mg pour homme acheter 25mg gГ©nГ©rique viagra en france generique sildenafil 200mg
cheap doxycycline 200mg buy clomid 100mg generic furosemide price
purchase ramipril online irbesartan oral astelin 10ml drug
buy generic buspirone 5mg amiodarone 100mg cost brand ditropan
alendronate 35mg uk order fosamax 70mg online cheap pepcid online
order molnunat generic buy molnupiravir without prescription buy prevacid 15mg online cheap
tadalafil 20mg oral buy prozac 20mg sildenafil dosage
cialis 40mg price order tadalafil for sale order symmetrel 100 mg generic
naltrexone 50 mg usa purchase abilify pill abilify 20mg canada
cialis for sales order generic betnovate buy anafranil 25mg sale
cost chloroquine 250mg olumiant 2mg ca baricitinib price
glycomet 1000mg oral female cialis tadalafil order cialis 10mg generic
norvasc online order tadalafil 20mg usa cialis 10mg drug
clozaril 100mg brand order ipratropium 100 mcg pill decadron 0,5 mg price
order omeprazole 20mg pills pay for essays online blackjack with real money
zyvox drug online casino gambling online casino roulette
clomid 100mg pills purchase albuterol without prescription best online poker sites
tadalafil pill usa viagra overnight viagra 50mg sale
order aristocort sale desloratadine online buy clarinex tablet
dapoxetine 90mg brand priligy price order synthroid 100mcg sale
cheap orlistat acyclovir 400mg brand zovirax for sale
order tadalafil 20mg generic order plavix 150mg pill purchase plavix without prescription
buy domperidone 10mg generic sumycin 250mg generic purchase flexeril generic
gloperba us play for real online casino games free casino games
buy ranitidine 300mg generic purchase zantac pill oral celecoxib 200mg
that roulette online blackjack game play casino games for cash
brand tamsulosin 0.2mg oral zofran spironolactone 100mg canada
metronidazole cost metronidazole online buy oral bactrim 480mg
diflucan over the counter sildenafil 100mg brand viagra online order
purchase cephalexin online cheap erythromycin 250mg uk erythromycin 250mg canada
tadalafil 5 mg tablet cialis 20mg uk viagra in usa
sildenafil medication buy viagra 100mg generic cialis online order
assignment website research paper website ivermectin 6mg
sildenafil pills purchase sildalis for sale order lamictal
buy prednisone sale isotretinoin 20mg without prescription order amoxicillin for sale
purchase sildenafil online buy sildenafil 50mg pills discount cialis
play roulette no deposit bonus codes cialis 10mg drug
recommended you read modafinil 200mg pills purchase provigil pill
sildenafil uk order tamoxifen 10mg pills buy rhinocort for sale
order prednisone 20mg generic vermox 100mg usa buy mebendazole for sale
order tretinoin gel sale tadalafil 10mg brand brand avana 100mg
terbinafine tablet terbinafine 250mg cost trimox 500mg pill
naproxen 500mg ca omnicef over the counter purchase lansoprazole generic
order spiriva 9 mcg without prescription minocycline brand purchase terazosin without prescription
montelukast 10mg cost viagra next day buy sildenafil 100mg online
real cialis tadalafil brand cialis generic name
order cialis 10mg generic Buy cialis empire city casino online
purchase stromectol stromectol 6mg brand order dapsone 100 mg online cheap
buy adalat 30mg buy aceon 8mg generic cheap fexofenadine 120mg
blackjack for money writing dissertation service paper writing online
order doxycycline 200mg without prescription order cleocin 300mg online cleocin for sale online
online assignment writer purchase leflunomide generic buy azulfidine generic
cost amoxicillin 1000mg stromectol 12mg over the counter ivermectin 12mg
purchase tadacip online cheap tadacip cost amoxicillin 250mg
buy esomeprazole 20mg generic biaxin drug lasix 100mg price
minocin usa order gabapentin without prescription brand hytrin 1mg
order glycomet 1000mg oral verapamil 240mg tamoxifen brand
prednisone 40mg pill isotretinoin 10mg oral order amoxicillin 1000mg pill
accutane 40mg cheap order ampicillin pill ampicillin 250mg drug
sildenafil 50mg canada finasteride oral order finasteride 1mg generic
buy accutane 20mg online buy accutane 40mg pills order zithromax generic
generic ventolin 4mg purchase levothroid for sale order augmentin 375mg for sale
prednisolone 10mg canada oral lasix order lasix without prescription
purchase doxycycline for sale buy levitra 10mg pills zovirax pills
order alfuzosin 10mg online uroxatral 10mg tablet order diltiazem sale
buy viagra 100mg generic discount tadalafil without prescription cialis daily
buy warfarin cheap coumadin 5mg generic buy allopurinol online cheap
buy generic zyrtec 10mg how to buy sertraline order sertraline pills
order letrozole sale sildenafil 100mg sildenafil on line
cialis 20mg price buy cialis 5mg without prescription can i buy ed pills over the counter
buy modafinil deltasone 10mg generic purchase deltasone online
buy amoxicillin 250mg sale order prednisolone 40mg pill prednisolone medication
accutane cheap buy generic zithromax 250mg azithromycin 250mg us
neurontin 100mg without prescription gabapentin 800mg drug vibra-tabs us
purchase vibra-tabs sale augmentin price amoxiclav pills
buy atenolol online cheap order femara 2.5 mg buy letrozole 2.5 mg pills
buy levothyroxine tablets buy synthroid online order vardenafil 20mg pill
order albendazole 400 mg online albenza cheap medroxyprogesterone 5mg canada
buy glucophage 500mg without prescription buy atorvastatin 40mg generic generic amlodipine 5mg
lisinopril 2.5mg for sale purchase omeprazole online metoprolol 100mg for sale
order methotrexate 5mg sale warfarin for sale online order metoclopramide 20mg online
order orlistat pills xenical for sale online order allopurinol 300mg
buy cheap generic hyzaar buy cozaar 25mg sale topiramate 100mg brand
purchase sumatriptan pills sumatriptan 50mg cost buy dutasteride medication
buy generic toradol buy cheap colcrys inderal 20mg cheap
zantac oral buy celebrex 200mg for sale generic celebrex 100mg
Thank you for great content. Hello Administ. Hacklink Panel Hacklink
betnovate 20gm sale order clomipramine generic order itraconazole pills
buy prometrium sale olanzapine 10mg cheap buy cheap olanzapine
buy carbamazepine 400mg without prescription oral tegretol order lincocin
generic cialis 5mg cialis 20mg cheap cheap sildenafil without prescription
buy duricef 500mg generic order lamivudine generic buy proscar 1mg for sale
cleocin pills erythromycin oral fda approved over the counter ed pills
bimatoprost online buy buy generic careprost for sale order desyrel 100mg for sale
buy lasix 40mg sale order doxycycline 200mg for sale order albuterol pills
levitra 20mg tablet tizanidine oral plaquenil oral
levitra 10mg tablet order levitra 10mg without prescription buy plaquenil 200mg pill
olmesartan 10mg us how to buy depakote buy divalproex 500mg pill
buy generic temovate for sale cheap clobetasol buy amiodarone generic
carvedilol 25mg without prescription purchase carvedilol generic aralen price
digoxin 250 mg sale telmisartan canada molnunat over the counter
order montelukast 10mg without prescription buy avlosulfon 100mg pill buy avlosulfon 100mg pill
nifedipine 30mg pill buy adalat 10mg for sale cost fexofenadine 120mg
buy generic norvasc 5mg buy norvasc no prescription order omeprazole without prescription
priligy us cytotec 200mcg drug order orlistat 120mg generic
aristocort order oral claritin claritin us
ampicillin price purchase ciprofloxacin online cheap metronidazole pills
purchase tetracycline generic tetracycline without prescription order lioresal pill
cost trimethoprim cephalexin 250mg pill order cleocin 300mg online
buy erythromycin without prescription order tamoxifen 10mg pill nolvadex 10mg price
purchase budesonide buy cefuroxime 250mg generic buy careprost without prescription
cheap avodart meloxicam pills meloxicam where to buy
lamotrigine 200mg pill buy cheap vermox prazosin order online
order aldactone 25mg online order zocor 10mg for sale valacyclovir sale
buy generic tretinoin gel buy retin gel online cheap buy avana sale
finasteride price proscar 5mg uk buy viagra 100mg pill
order tadalafil 10mg sale cialis 40mg brand buy ed meds
generic terbinafine amoxicillin 500mg pills buy generic amoxicillin 250mg
order antivert online cheap meclizine without prescription order minocycline 100mg capsules
cheap ed drugs sildenafil overnight shipping usa brand viagra
top rated ed pills cialis 20mg sale buy tadalafil 40mg sale
buy avlosulfon 100 mg for sale oral dapsone buy cheap generic aceon
allegra 180mg cheap buy amaryl 4mg generic order amaryl 4mg online cheap
buy hytrin cheap order leflunomide 20mg generic order cialis 5mg for sale
order arcoxia 120mg without prescription order arcoxia sale astelin 10 ml uk
order irbesartan 150mg sale order buspirone for sale buspirone 10mg price
buy albendazole 400mg for sale purchase albenza pill provera where to buy
buy biltricide 600 mg online cheap order microzide pills buy periactin for sale
tacrolimus cheap remeron brand ropinirole 1mg for sale
buy oxcarbazepine generic brand alfuzosin order generic ursodiol 300mg
buy decadron 0,5 mg without prescription purchase decadron online cheap buy starlix 120mg generic
zyban 150 mg drug buy strattera 10mg pill cost atomoxetine
buy captopril generic buy atacand 8mg pills tegretol 200mg generic
buy ciprofloxacin without a prescription cefadroxil 500mg canada order cefadroxil
fluoxetine 40mg cost generic revia brand letrozole
buy frumil 5 mg purchase differin sale order acyclovir creams
how to buy bisoprolol zebeta 5mg drug order oxytetracycline