【发布时间】:2016-02-21 01:22:37
【问题描述】:
在 PHP 如何正则表达式 preg_match 来自相同类型和值标签的特定标签值。
这里有一些 html 标签,我想通过正则表达式 preg_match 获取最后一个标签值
</tr>
<tr class="flow">
<td>14.1%</td>
<td>13.2%</td>
<td>13.6%</td>
<td>14.1%</td>
<td>14.0%</td>
<td>14.0%</td>
<td>14.1%</td> <== i want to fetch this last <td> tag value with regex, how ?
</tr>
</tbody>
If I preg_match `'/<tr class="flow">(.*?)<\/td>/s'`;
but then it will fetch first `<td>` tag value
and if preg_match `'/<td>(.*?)<\/td>/s'`;
then it will fetch all `<td>` tags values.
So how I can fetch last `<td>` value?
I mean I want something like to `preg_match` in reverse mode
like this `'/</tbody>(.*?)<\td>/s'`; or maybe anything else to do?
This is the small part of page and page contain 100's of other <td> tags
so you must have to do something preg_match with
between </tbody> and <td> in reverse mode ...OR..
Between <tr class="flow"> </tbody> in forward mode.
但我不知道怎么做?您的帮助将不胜感激。
【问题讨论】:
-
不,你的回答并不能解决我的问题,这很复杂,难以理解。所以请在这里给我一个例子,我如何 preg_match 最后一个
标记值。我必须使用什么公式?
标签: php html regex preg-match