PHP正则表达式从HTML表格中提取数据 [英] php regex to extract data from HTML table

查看:145
本文介绍了PHP正则表达式从HTML表格中提取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我现在得到的代码是:

 < table> 
< tr>
< td> quote1< / td>
< td>是否尝试关闭并再次开启?< / td>
< / tr>
< tr>
< td> quote65< / td>
< td>你不会偷一个警察的头盔< / td>
< / tr>
< / table>

这个我想替换为:

quote1:你有试过它吗?



quote65:你不会偷一个警察的头盔

我已经写过的代码是这样的:

 %< td>((?s)。* ?)< / td>%

但现在我被卡住了。

解决方案

Tim的正则表达式可能有效,但您可能需要考虑使用PHP的DOM功能而不是正则表达式,因为它可能在处理次要标记的变化。



参见 loadHTML方法


I'm trying to make a regex for taking some data out of a table.

the code i've got now is:

<table>
   <tr>
     <td>quote1</td>
     <td>have you trying it off and on again ?</td>
   </tr>
   <tr>
     <td>quote65</td>
     <td>You wouldn't steal a helmet of a policeman</td>
   </tr>
</table>

This I want to replace by:

quote1:have you trying it off and on again ?

quote65:You wouldn't steal a helmet of a policeman

the code that I already have written is this:

%<td>((?s).*?)</td>%

But now I'm stuck.

解决方案

Tim's regex probably works, but you may want to consider using the DOM functionality of PHP instead of regex, as it may be more reliable in dealing with minor changes in the markup.

See the loadHTML method

这篇关于PHP正则表达式从HTML表格中提取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆