正则替换提取字符串
<divclass="c1"><strong>地区:</strong><ahref="/lawyers/0/">不限</a><strongstyle=color:gree...
<div class="c1"><strong>地区:</strong><a href="/lawyers/0/">不限</a> <strong style=color:green>北京市</strong> <a href="/lawyers/2/">上海市</a> <a href="/lawyers/3/">天津市</a> <a href="/lawyers/4/">重庆市</a> <a href="/lawyers/5/">广东省</a> <a href="/lawyers/6/">福建省</a> <a href="/lawyers/7/">浙江省</a> <a href="/lawyers/8/">江苏省</a> <a href="/lawyers/9/">山东省</a> <a href="/lawyers/10/">辽宁省</a> <a href="/lawyers/11/">江西省</a> <a href="/lawyers/12/">四川省</a> <a href="/lawyers/13/">陕西省</a> <a href="/lawyers/14/">湖北省</a> <a href="/lawyers/15/">河南省</a> <a href="/lawyers/16/">河北省</a> <a href="/lawyers/17/">山西省</a> <a href="/lawyers/18/">内蒙古</a> <a href="/lawyers/19/">吉林省</a> <a href="/lawyers/20/">黑龙江</a> <a href="/lawyers/21/">安徽省</a> <a href="/lawyers/22/">湖南省</a> <a href="/lawyers/23/">广西区</a> <a href="/lawyers/24/">海南省</a> <a href="/lawyers/25/">云南省</a> <a href="/lawyers/26/">贵州省</a> <a href="/lawyers/27/">西藏区</a> <a href="/lawyers/28/">甘肃省</a> <a href="/lawyers/29/">宁夏区</a> <a href="/lawyers/30/">青海省</a> <a href="/lawyers/31/">新疆区</a> <a href="/lawyers/32/">香港区</a> <a href="/lawyers/33/">澳门区</a> <a href="/lawyers/35/">台湾省</a> </div><div class="c2"><strong style=color:green>西城区</strong> <a href="/lawyers/3116/">崇文区</a> <a href="/lawyers/104/">宣武区</a> <a href="/lawyers/105/">朝阳区</a> <a href="/lawyers/106/">海淀区</a> <a href="/lawyers/107/">丰台区</a> <a href="/lawyers/108/">石景山区</a> <a href="/lawyers/109/">门头沟区</a> <a href="/lawyers/110/">房山区</a> <a href="/lawyers/111/">通州区</a> <a href="/lawyers/112/">顺义区</a> <a href="/lawyers/113/">昌平区</a> <a href="/lawyers/114/">大兴区</a> <a href="/lawyers/115/">平谷县</a> <a href="/lawyers/116/">怀柔县</a> <a href="/lawyers/117/">密云县</a> <a href="/lawyers/118/">延庆县</a> <a href="/lawyers/3117/">东城区</a> </div>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
把文中<strong style=color:green>北京市</strong> 带这个的提取出来,
最后的结果是 北京市西城区 展开
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
把文中<strong style=color:green>北京市</strong> 带这个的提取出来,
最后的结果是 北京市西城区 展开
1个回答
展开全部
<?php
$test = '<div class="c1"><strong>地区:</strong><a href="/lawyers/0/">不限</a> <strong style=color:green>北京市</strong> <a href="/lawyers/2/">上海市</a> <a href="/lawyers/3/">天津市</a> <a href="/lawyers/4/">重庆市</a> <a href="/lawyers/5/">广东省</a> <a href="/lawyers/6/">福建省</a> <a href="/lawyers/7/">浙江省</a> <a href="/lawyers/8/">江苏省</a> <a href="/lawyers/9/">山东省</a> <a href="/lawyers/10/">辽宁省</a> <a href="/lawyers/11/">江西省</a> <a href="/lawyers/12/">四川省</a> <a href="/lawyers/13/">陕西省</a> <a href="/lawyers/14/">湖北省</a> <a href="/lawyers/15/">河南省</a> <a href="/lawyers/16/">河北省</a> <a href="/lawyers/17/">山西省</a> <a href="/lawyers/18/">内蒙古</a> <a href="/lawyers/19/">吉林省</a> <a href="/lawyers/20/">黑龙江</a> <a href="/lawyers/21/">安徽省</a> <a href="/lawyers/22/">湖南省</a> <a href="/lawyers/23/">广西区</a> <a href="/lawyers/24/">海南省</a> <a href="/lawyers/25/">云南省</a> <a href="/lawyers/26/">贵州省</a> <a href="/lawyers/27/">西藏区</a> <a href="/lawyers/28/">甘肃省</a> <a href="/lawyers/29/">宁夏区</a> <a href="/lawyers/30/">青海省</a> <a href="/lawyers/31/">新疆区</a> <a href="/lawyers/32/">香港区</a> <a href="/lawyers/33/">澳门区</a> <a href="/lawyers/35/">台湾省</a> </div><div class="c2"><strong style=color:green>西城区</strong> <a href="/lawyers/3116/">崇文区</a> <a href="/lawyers/104/">宣武区</a> <a href="/lawyers/105/">朝阳区</a> <a href="/lawyers/106/">海淀区</a> <a href="/lawyers/107/">丰台区</a> <a href="/lawyers/108/">石景山区</a> <a href="/lawyers/109/">门头沟区</a> <a href="/lawyers/110/">房山区</a> <a href="/lawyers/111/">通州区</a> <a href="/lawyers/112/">顺义区</a> <a href="/lawyers/113/">昌平区</a> <a href="/lawyers/114/">大兴区</a> <a href="/lawyers/115/">平谷县</a> <a href="/lawyers/116/">怀柔县</a> <a href="/lawyers/117/">密云县</a> <a href="/lawyers/118/">延庆县</a> <a href="/lawyers/3117/">东城区</a> </div>';
$test = preg_replace("/.*green>(.+)<\/strong.*green>(.+)<\/strong>.*/","$1$2",$test);
print $test;
?>
$test = '<div class="c1"><strong>地区:</strong><a href="/lawyers/0/">不限</a> <strong style=color:green>北京市</strong> <a href="/lawyers/2/">上海市</a> <a href="/lawyers/3/">天津市</a> <a href="/lawyers/4/">重庆市</a> <a href="/lawyers/5/">广东省</a> <a href="/lawyers/6/">福建省</a> <a href="/lawyers/7/">浙江省</a> <a href="/lawyers/8/">江苏省</a> <a href="/lawyers/9/">山东省</a> <a href="/lawyers/10/">辽宁省</a> <a href="/lawyers/11/">江西省</a> <a href="/lawyers/12/">四川省</a> <a href="/lawyers/13/">陕西省</a> <a href="/lawyers/14/">湖北省</a> <a href="/lawyers/15/">河南省</a> <a href="/lawyers/16/">河北省</a> <a href="/lawyers/17/">山西省</a> <a href="/lawyers/18/">内蒙古</a> <a href="/lawyers/19/">吉林省</a> <a href="/lawyers/20/">黑龙江</a> <a href="/lawyers/21/">安徽省</a> <a href="/lawyers/22/">湖南省</a> <a href="/lawyers/23/">广西区</a> <a href="/lawyers/24/">海南省</a> <a href="/lawyers/25/">云南省</a> <a href="/lawyers/26/">贵州省</a> <a href="/lawyers/27/">西藏区</a> <a href="/lawyers/28/">甘肃省</a> <a href="/lawyers/29/">宁夏区</a> <a href="/lawyers/30/">青海省</a> <a href="/lawyers/31/">新疆区</a> <a href="/lawyers/32/">香港区</a> <a href="/lawyers/33/">澳门区</a> <a href="/lawyers/35/">台湾省</a> </div><div class="c2"><strong style=color:green>西城区</strong> <a href="/lawyers/3116/">崇文区</a> <a href="/lawyers/104/">宣武区</a> <a href="/lawyers/105/">朝阳区</a> <a href="/lawyers/106/">海淀区</a> <a href="/lawyers/107/">丰台区</a> <a href="/lawyers/108/">石景山区</a> <a href="/lawyers/109/">门头沟区</a> <a href="/lawyers/110/">房山区</a> <a href="/lawyers/111/">通州区</a> <a href="/lawyers/112/">顺义区</a> <a href="/lawyers/113/">昌平区</a> <a href="/lawyers/114/">大兴区</a> <a href="/lawyers/115/">平谷县</a> <a href="/lawyers/116/">怀柔县</a> <a href="/lawyers/117/">密云县</a> <a href="/lawyers/118/">延庆县</a> <a href="/lawyers/3117/">东城区</a> </div>';
$test = preg_replace("/.*green>(.+)<\/strong.*green>(.+)<\/strong>.*/","$1$2",$test);
print $test;
?>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询