php 正则 ereg_replace替换

ereg_replace — 正则表达式替换(php 3,php 4,php 5)

string ereg_replace(string pattern,string replacement,string string)

本函数在 string 中扫描与 pattern 匹配的部分,并将其替换为 replacement,返回替换后的字符串,(如果没有可供替换的匹配项则会返回原字符串):

  1. <?php 
  2. $string = "this is a test"
  3. echo str_replace(" is"" was"$string); 
  4. echo ereg_replace("( )is""1was"$string); 
  5. echo ereg_replace("(( )is)""2was"$string); 
  6. ?> 
  7. //输出如下: 
  8. //that was a test 
  9. //that was a test 
  10. //that was a test 

<td class='title'>热卖oou限量版双人浴巾</td>

整个替换为空,还是将

<td class='title'>热卖oou限量版双人浴巾</td>

替换成

<td class='title'></td>

第一种:echo preg_replace('/(<td[^<>]+title[^<>]+>)[^<>]*(</td>)/i', '', $html);

第二种:echo preg_replace('/(<td[^<>]+title[^<>]+>)[^<>]*(</td>)/i', '$1$2', $html);

首先这个正则表达式匹配 类似格式:

<td*title*>*</td>,这里每个星号*代表的是多个任意字符,相当于每个*对应正则里的[^<>]+,为了匹配准确,这里任意字符里不包含'<','>'.

对于第二种里的替换字符串$1和$2,分别为正则表达式里对应的两组()内匹配的值.这种形式正则里叫 子模式匹配.$1和$2叫反向匹配的结果.

这里$1匹配的结果是<td class='title'>,$2匹配的结果是</td>.

波比源码 – 精品源码模版分享 | www.bobi11.com
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 本站源码并不保证全部能正常使用,仅供有技术基础的人学习研究,请谨慎下载
8. 如遇到加密压缩包,请使用WINRAR解压,如遇到无法解压的请联系管理员!

波比源码 » php 正则 ereg_replace替换

135 评论

  1. buy revia 50 mg online cheap buy revia 50 mg buy abilify generic

  2. sildenafil citrate 50mg viagra for sale buy lisinopril without prescription

  3. order cialis 10mg pills viagra brand viagra brand

  4. buy losartan 50mg without prescription topamax online topamax uk

  5. buy deltasone 10mg online cheap vermox order vermox 100mg canada

  6. buy generic pioglitazone 30mg sildenafil sale sildenafil viagra

  7. order cialis 5mg generic Cialis visa casino gambling

  8. prednisolone 10mg for sale furosemide sale furosemide 40mg tablet

  9. provigil 200mg generic oral modafinil order metoprolol 50mg pills

  10. ventolin for sale oral augmentin order levothyroxine for sale

  11. glucophage 1000mg price order norvasc 5mg where can i buy amlodipine

  12. ketorolac tablet buy gloperba buy inderal generic

  13. order betamethasone 20gm without prescription anafranil 50mg usa buy generic itraconazole

  14. metronidazole 200mg price brand septra oral cephalexin 250mg

  15. order amoxicillin 500mg without prescription arimidex price order generic biaxin 250mg

  16. careprost for sale buy robaxin desyrel 100mg for sale

  17. where can i buy clobetasol buspar online oral cordarone 200mg

  18. brand acetazolamide 250mg imuran 25mg usa imuran 25mg pills

  19. brand tadalafil 20mg viagra 25 mg viagra canada

  20. order generic tadalafil 20mg tadalafil brand buy ed pills for sale

  21. buy generic fexofenadine online buy allegra buy generic amaryl over the counter

  22. buy avapro 150mg without prescription cost clobetasol purchase buspar pill

  23. order generic luvox ketoconazole oral order cymbalta 40mg without prescription

  24. order captopril 25mg sale carbamazepine ca buy generic tegretol for sale

  25. buy ciprofloxacin 500 mg online cheap buy lincocin online duricef 250mg over the counter

评论已关闭

Hi, 如果你对这款模板有疑问,可以跟我联系哦!

联系站长
赞助VIP 享更多特权,建议使用 QQ 登录
喜欢我嘛?喜欢就按“ctrl+D”收藏我吧!♡