2014-03-25 40 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