[英]PHP regular expression to extract html values
I want to extract values from the code below. 我想从下面的代码中提取值。
<tbody>
<tr>
<td><div class="file_pdf"><a href="javascript:downloadFile('1628')">note1</a></div></td>
<td class="textright">110 KB</td>
<td class="textright">106</td>
</tr>
<tr>
<td><div class="file_pdf"><a href="javascript:downloadFile('1629')">note2.pdf</a></div></td>
<td class="textright">44 KB</td>
<td class="textright">104</td>
</tr>
</tbody>
I want to extract 'note1', 'note2' strings and 1628 and 1629 numbers. 我想提取“ note1”,“ note2”字符串以及1628和1629数字。
i treid 我畏惧
preg_match_all('~(\'\)\">(.*?)<\/a>)~', $getinside, $matches);
but its result is not what I am looking for.. 但是它的结果不是我想要的。
is there any simple RegEx to extract them? 有没有简单的RegEx提取它们? Thanks!
谢谢!
It should work for you: 它应该为您工作:
preg_match_all("~downloadFile\('(\d+)'\)\">([^<]*)</a>~", $getinside, $matches);
Remember: If your html is very large/complex and you also need to parse more other things from there, then regex is not a better option to do this. 请记住:如果您的html非常大/复杂,并且您还需要从那里解析更多其他内容,那么regex不是更好的选择。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.