2014-03-25 38 views
1

我从file_get_contents的外部网站拉日历,所以我可以使用它的jQuery .load。php preg_match_all开头为?

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

这样算下来

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

获取我的<a href = '' 所有出现什么我都只是在单引号内的链接后。 现在,每条链接以“?date”开头,因此我有<a href='?date=4%2F9%2F2014&a'等。

如何在所有<a href=事件中高效获取单引号之间的字符串。

回答

2

使用Dom parser来从<a>标签

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

在href这就是做这件事的另一种方式,而且比我如何开始绕了好多。谢谢! – bing

+0

@bing很高兴帮助 – Nambi