preg match all - php preg_match_all words starting with?


preg match all - php preg_match_all words starting with?

我从file_get_contents的外部站点拉入一个日历,所以我可以使用jQuery .load。

为了解决这种方法的相对路径问题,我使用preg_match_all .

preg_match_all("/<a href='([^'"]*)'/iU", $string, $match);

显示<a href = ''的所有出现情况我所追求的只是单引号内的链接。现在每个链接都以"?"所以我有<a href='?date=4%2F9%2F2014&a'等。

如何在所有<a href=中有效地获得单引号之间的字符串

使用 Dom parser <a>标签获取href

<?php
$file =  "your.html";
$doc = new DOMDocument();
$doc->loadHTMLFile($file);
$elements = $doc->getElementsByTagName('a');
foreach ($elements as $tag) {
    echo $tag->getAttribute('href');
}