我想从以下值中获取 2014 年 12 月
<tr>
<th rowspan="2" scope="row">Launch</th>
<td class="ttl"><a href=# onClick="helpW('h_year.htm');">Announced</a></td>
<td class="nfo">2014, December</td>
</tr>
我使用以下代码来获得它,但没有任何成功
preg_match_all("/Announced<'/a><'/td><td class='"nfo'">(.*?)<'/td>/m", $input_lines, $output_array);
我尝试了/./s 代替 x,但没有运气。我需要你的建议。
PS:我无法使用DOM解析器,因为我已经有很多模式准备好根据我的需要使用正则表达式提取字符串。
编辑:现在这也解决了我的问题
preg_match_all("/(Announced<'/a><'/td>).*?(<td class='"nfo'">)(.*?)<'/td>/s", $input_lines, $output_array);
您忘记在正则表达式中添加中间的'n
字符。
preg_match_all("~Announced<'/a><'/td>'n<td class='"nfo'">(.*?)<'/td>~m", $input_lines, $output_array);
^
|
演示