我需要帮助php preg模式从以下数据中提取内容:
<div class="box">
<div>
<a href="/;s=-w3NKGFjkswdkjbg0B;detail=person;id=937382/me">
<b>Smith, Johnny</b>
</a>
</div>
<div>
<a href="/;s=-w3NKGFjkswdkjbg0B/http%3aservice.myxyz.net/ch/cgi/g.fcgi/me/new?CUSTOMERNO=836327973&t=i373u.1310541179.a1ecb28b&TO=smithjohnny@gmail.com">smithjohnny@gmail.com</a>
</div>
<div>
<a href="/;s=-w3NKGFjkswdkjbg0B;edit=person;id=937382/me"><img src="/;m=is;f=gif89a;h=18;k=sdakjdk12eksack;w=18/it%3amfitmcsfe19/DiEDzr48XbZcjfyGLMKnzw.gif" alt="" width="18" height="18">
</a>
<a href="/;s=-w3NKGFjkswdkjbg0B;delete=person;id=937382/me">
<img src="/;m=is;f=gif89a;h=18;k=Dk3k-kVox-ads9Lopt-yBQ;w=18/it%3amfitmcsfe19/tHJTBPhousrElDf1x5aPvA.gif" alt="" width="18" height="18">
</a>
</div>
<div class="fitMlModuleLinec8fe6cf8"> </div>
<div>
<a href="/;s=-w3NKGFjk4jkedkds8g0B;detail=person;id=327843287/me"></a>
</div>
<div>
<a href="/;s=-w3NKGFjk4jkedkds8g0B/http%3aservice.myxyz.net/ch/cgi/g.fcgi/me/new?CUSTOMERNO=98324826438&t=de13929382.1310541179.a1ecb28b&TO=iamtesting@gmail.com">iamtesting@gmail.com</a>
</div>
<div>
<a href="/;s=-w3NKGFjk4jkedkds8g0B;edit=person;id=327843287/me">
<img src="/;m=is;f=gif89a;h=18;k=cBoj9wS5Yp5345435EREg;w=18/it%3amfitmcsfe19/DiEDzr48XbZcjfyGLMKnzw.gif" alt="" width="18" height="18"></a> |
<a href="/;s=-w3NKGFjk4jkedkds8g0B;delete=person;id=327843287/me">
<img src="/;m=is;f=gif89a;h=18;k=Dk3k-kVox-ads9Lopt-yBQ;w=18/it%3amfitmcsfe19/tHJTBPhousrElDf1x5aPvA.gif" alt="" width="18" height="18"></a>
</div>
<div class="fitMlModuleLinec8fe6cf8"> </div>
<div>
<a href="/;s=-w3NKGsndqw21g0B;detail=person;id=83467836/me">
<b>Parker</b>
</a>
</div>
<div>
<a href="/;s=-w3NKGsndqw21g0B;edit=person;id=83467836/me">
<img src="/;m=is;f=gif89a;h=18;k=cBodejksa23KNKvUEREg;w=18/it%3amfitmcsfe19/DiEDzr48XbZcjfyGLMKnzw.gif" alt="" width="18" height="18"></a> |
<a href="/;s=-w3NKGF6hSNhymOcg6uWbg0B;delete=person;id=83467836/me">
<img src="/;m=is;f=gif89a;h=18;k=Dk3k-kVox-ads9Lopt-yBQ;w=18/it%3amfitmcsfe19/tHJTBPhousrElDf1x5aPvA.gif" alt="" width="18" height="18"></a>
</div>
<div class="fitMlModuleLinec8fe6cf8"> </div>
</div>
</div>
以上数据如下所示:
以下是条件:
输出数组应如下所示:
Array(
[email#1]= array([name]='name'),
[email#2]= array([name]='name')
.
.
[email#n]= array([name]='name')
)
上述数据的结果应如下所示:
Array(
[smithjohnny@gmail.com]= array([name]='Smith, Johnny'),
[iamtesting@gmail.com]= array([name]='')
)
请为我提出针对上述问题的最高优化preg_match
。
答案 0 :(得分:0)
我对数据的质量做了一些假设,但你可以
preg_match("/<a href=\".+?\">([^<]+)@([^<]+)</a>", "smithjonny@gmail.com", $matches);
// $matches[1]='smithjonny'
// $matches[2]='gmail.com'
这有点粗糙,但如果您可以保证href
不包含"
(应该将其移除到"
),那么它将提取电子邮件。< / p>