【发布时间】:2023-03-27 18:24:02
【问题描述】:
我正在尝试使用正则表达式从 HTML 文件中提取多个 URL。 文件中还有其他 URL,我唯一的模式是“tableentries”。和“”
HTML 代码示例:
<tr class="tableentries2">
<td>
<a href="http://example.com/all-files/files/00000000789/">Click Here</a>
</td>
我写的PHP:
$html = "value of the code above"
if(preg_match_all('/<td>.*</td>/', $html, $match)){
foreach($match[0] as $x){
echo $x . "<br>";
}}
【问题讨论】:
-
您的问题到底是什么?这段代码能给你带来什么?为什么它不起作用?
-
HTML 属性周围缺少引号。
<tr class="tableentries2"> ... <a href="http://example.com/...">(编辑你的问题) -
也许可以使用像simplehtmldom.sourceforge.net这样的DOM解析器