ワードプレスに移行できるように、クライアントのサイトのホームページのすべての URL をスクレイピングしようとしています。問題は、重複除去された URL のリストに到達できないように見えることです。
コードは次のとおりです。
$html = file_get_contents('http://www.catwalkyourself.com');
$dom = new DOMDocument();
@$dom->loadHTML($html);
// grab all the on the page
$xpath = new DOMXPath($dom);
$hrefs = $xpath->evaluate("/html/body//a");
for ($i = 0; $i < $hrefs->length; $i++) {
$href = $hrefs->item($i);
$url = $href->getAttribute('href');
if($url = preg_match_all('((www|http://)(www)?.catwalkyourself.com\/?.*)', $url, $matches[0])){
$urls = $matches[0][0][0];
$list = implode( ', ', array_unique( explode(", ", $urls) ) );
echo $list . '<br/>';
//print_r($list);
}
}
(こちらにも掲載しています。)
代わりに、次のような重複が発生しています。
http://www.catwalkyourself.com/rss.php
http://www.catwalkyourself.com/rss.php
これを修正するにはどうすればよいですか?