[英]in PHP How to regex preg_match specific HTML tag value from same type value tags
PHP中的regex 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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.