in 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('|'<tr class="flow"'>(.*?)'</tr'>|s', $input_text, $match);
$filterd_input_text = $match[1];
preg_match_all('|'<td'>(.*?)'</td'>|', $filterd_input_text, $matches);
$value = end($matches[1]);
var_dump($value);
或
preg_match_all('|<td>(.*?)</td>.*</tbody>|s', $t, $matches);