使用php进行数据解析检索
假设我们的网页有以下结构。如何使用 php 检索以下信息? 某物 XAXAXA-莎莎莎 2-1 扎扎扎扎-卡卡卡卡 2-2
<th class='black' colspan='6'>something</th>
<tr class=''>
<td bgcolor = '#272727' width = 40%>XAXAXA</td>
<td bgcolor = '#272727' width = '5%'> - </td>
<td bgcolor = '#272727' width = '40%'>SASASASA</td>
<td bgcolor = '#272727' width = '5%'>2</td>
<td bgcolor = '#272727' width = '5%'> - </td>
<td bgcolor = '#272727' width = '5%'>1</td>
</tr>
<tr class=''>
<td bgcolor = '#484848' width = 40%>ZAZAZAZA</td>
<td bgcolor = '#484848' width = '5%'> - </td>
<td bgcolor = '#484848' width = '40%'>CACACACA</td>
<td bgcolor = '#484848' width = '5%'>2</td>
<td bgcolor = '#484848' width = '5%'> - </td>
<td bgcolor = '#484848' width = '5%'>2</td>
</tr>
Lets say we have the following structure in a web page. How can i retrieve the following information using php?
something
XAXAXA-SASASASA 2-1
ZAZAZAZA-CACACACA 2-2
<th class='black' colspan='6'>something</th>
<tr class=''>
<td bgcolor = '#272727' width = 40%>XAXAXA</td>
<td bgcolor = '#272727' width = '5%'> - </td>
<td bgcolor = '#272727' width = '40%'>SASASASA</td>
<td bgcolor = '#272727' width = '5%'>2</td>
<td bgcolor = '#272727' width = '5%'> - </td>
<td bgcolor = '#272727' width = '5%'>1</td>
</tr>
<tr class=''>
<td bgcolor = '#484848' width = 40%>ZAZAZAZA</td>
<td bgcolor = '#484848' width = '5%'> - </td>
<td bgcolor = '#484848' width = '40%'>CACACACA</td>
<td bgcolor = '#484848' width = '5%'>2</td>
<td bgcolor = '#484848' width = '5%'> - </td>
<td bgcolor = '#484848' width = '5%'>2</td>
</tr>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 DOMDocument 来实现此目的,非常简单:
You can use DOMDocument for this, pretty simple:
您可以使用正则表达式来匹配这样的模式。 preg_match() 函数是一个很好的起点。
You can use a regular expression to match a pattern like that. The preg_match() function is a good place to start.
希望这次您能接受答案!只需拉出第 1 至 13 组比赛即可。
结果:
I hope you accept an answer this time! Just pull out the match groups 1 to 13.
Result: