function get_link_and_anchor($url_awal) {
$html = file_get_html($url_awal);
$dom = new DOMDocument();
@$dom->loadHTML($html);
$anchors = $dom->getElementsByTagName('a');
foreach ($anchors as $anchor) {
$url_dari_konten = $anchor->getAttribute('href');
$urltext = $anchor->nodeValue;
$url_hasil = url_to_absolute(@$url_awal, @$url_dari_konten);
echo $urltext . " : " . $url_hasil . "<br/>";
}
}
结果:
推特:ht*ps://twitter.com/batagrams
Google+:ht*ps://plus.google.com/115711571208014927563
主页:ht*p://batagrams.com/
关于:ht*p:/ /batagrams.com/about
培训:ht*p://batagrams.com/training
新闻:ht*p://batagrams.com/news
我只想得到:
主页:ht*p://batagrams.com/
关于:ht*p://batagrams.com/about
培训:ht*p://batagrams.com/training
新闻:ht*p:/ /batagrams.com/news
我正在使用 PHP Simple HTML DOM Parser 和 url_to_absolute