语法: mixed preg_replace(mixed pattern, mixed replacement, mixed subject);
内容说明: 本函数以 pattern 的规则来解析比对字符串 subject,欲取而代之的字符串为参数replacement。返回值为混合类型资料,为取代后的字符串结果。
一,preg_replace():
$msg = preg_replace("/<style>.+</style>/is", "", $msg);//删除<style></style>和中间的部
$msg = preg_replace("/<[^>]+>/", "", $msg); //删除<>和中间的内容
i (PCRE_CASELESS):如果设定此修正符,模式中的字符将同时匹配大小写字母。
s (PCRE_DOTALL):如果设定了此修正符,模式中的圆点元字符(.)匹配所有的字符,包括换行符。没有此设定的话,则不包括换行符。这和 Perl 的 /s 修正符是等效的。排除字符类例如 [^a] 总是匹配换行符的,无论是否设定了此修正符。
二,ereg()与eregi()
注:preg_match() 函数通常是比 ereg() 更快的替代方案
eregi("<body([^>]+)>(.+)</body>",$data,$b)//察看$data中是否有body标签,如果有,把参数赋值$b[0],中间部分赋值$b[1]。
bool ereg ( string pattern, string string [, array regs] )
int eregi ( string pattern, string string, array [regs] )
eregi()和 ereg() 类似,用法也相同,不同之处在于ereg()有区分大小写,eregi()与大小写无关
- <?php
- //preg_replace()和ereg_replace()函数的使用的比较
- // ——-preg_replace()————————–
- //1.进行字符串的查找的替换
- $str = "daoyu shi ge hao hai zi 5555";
- $pattern = "/s/"; //如果将变量定义为$pattern_1会出错
- $str = preg_replace($pattern,'-',$str);
- echo $str."<br>";
- //2.对字符串的逆向引用
- //方法一
- $pat = "/(w+)-(w+)-(w+)-(w+)-(w+)-(w+)-(d+)/i";
- $str =preg_replace($pat,"$1",$str);
- echo $str."<br>";
- //注意:如果是下面这种形式你会发现匹配的是:zi- 所以可以这样认为在有次数的{6}的情况下,他($1)匹配的是最后一次
- $pat = "/((w+)-){6}(d+)/i";
- $str =preg_replace($pat,"$1",$str);
- echo $str."<br>";
- //方法二
- $str = "daoyu-shi-ge-hao-hai-zi-5555";
- $pat = "/(w+)-(w+)-(w+)-(w+)-(w+)-(w+)-(d+)/i";
- $str =preg_replace($pat,"1",$str);
- echo $str."<br>";
- //注意:当正则写成$pat= "/((w+)-){6}(d+)/i";时和上面的情况一样
- ?>
波比源码 » PHP字符串正则替换函数preg_replace
levofloxacin 500mg pill buy levofloxacin 250mg generic
buy tadalafil 20mg sale order diclofenac 50mg online voltaren 50mg sale
order catapres online cheap minocycline 100mg generic buy spiriva 9mcg generic
buy bupropion 150 mg for sale order zyban 150 mg generic cheap seroquel
cost molnupiravir 200mg brand naprosyn 250mg buy lansoprazole generic
dapsone 100 mg brand nifedipine usa order perindopril generic
provigil 100mg tablet stromectol 6mg pill ivermectin 12 mg otc
zithromax for sale azithromycin drug cheap neurontin tablets
clozapine over the counter buy ipratropium pill order decadron 0,5 mg online
order zyvox pills can you play poker online money free online poker games
lopressor 50mg cheap atenolol 100mg cheap buy vardenafil 20mg online
buy vardenafil generic order levitra 10mg generic buy methylprednisolone 4 mg
brand cialis pills sildenafil 50mg ca purchase viagra online cheap
purchase orlistat generic order acyclovir 400mg cost acyclovir
cost zyloprim order crestor 20mg online cheap zetia 10mg generic
order methotrexate 5mg pills purchase methotrexate without prescription brand reglan 10mg
buy colchicine pills casino world real casino slots online
order cialis 20mg sale viagra medication cheap viagra tablets
best online blackjack real money oral cialis 20mg generic tadalafil 40mg
trazodone 100mg pills aurogra 50mg brand buy aurogra 100mg
prednisone 10mg generic cost prednisone 40mg buy amoxicillin 1000mg sale
order zithromax generic order generic neurontin cost gabapentin
order retin without prescription avanafil 200mg cost avana order
cheap tadalafil 10mg cost voltaren 100mg indocin 50mg brand
clarithromycin buy online buy biaxin 500mg pills buy meclizine pill
buy tiotropium bromide 9mcg pills buy spiriva 9mcg terazosin tablet
singulair buy online viagra 200mg price sildenafil 50mg cheap
cialis 10mg usa Samples of cialis play poker online free no sign up
play roulette free for fun roulette online free online slots real money
play real poker online fda approved canadian online pharmacies how to write a letter to a hiring manager
buy generic asacol 400mg avapro 150mg cost avapro without prescription
purchase benicar generic purchase divalproex pill order divalproex generic
acetazolamide canada isosorbide ca azathioprine 50mg usa
order digoxin without prescription order digoxin 250 mg sale cheap molnunat
order carvedilol 25mg online cheap cost coreg 25mg generic elavil
buy fosamax online cheap order alendronate 35mg online cheap ibuprofen price
indomethacin 50mg drug buy cenforce 100mg cenforce 50mg canada
purchase requip online buy trandate pill trandate 100mg generic
fenofibrate 160mg pill sildenafil 50mg generic buy viagra 100mg pills
order nexium 20mg without prescription buy esomeprazole generic order lasix 40mg pill
cheap tadalafil 20mg Buy discount cialis order sildenafil
cialis 10mg for sale online ed pills medicine for impotence
order generic prednisone 40mg order amoxil for sale generic amoxil 250mg
order accutane 40mg without prescription ampicillin without prescription order ampicillin 500mg without prescription
zofran online order buy zofran 4mg generic bactrim us