이 그것을 할 (또는 도움이 적어도됩니다) :
$pageRaw = fread_url('www.example.com');
//link extraction regex
preg_match_all ("/a[\s]+[^>]*?href[\s]?=[\s\"\']+".
"(.*?)[\"\']+.*?>"."([^<]+|.*?)?<\/a>/",
$pageRaw, &$matches);
$matches = $matches[1];
foreach($matches as $link)
{
echo $link. '<br />';
}
//falls back to fopen if curl is not there
function fread_url($url,$ref="")
{
if(function_exists("curl_init")){
$ch = curl_init();
$user_agent = "Mozilla/4.0 (compatible; MSIE 5.01; ".
"Windows NT 5.0)";
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_HTTPGET, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION , 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION , 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_REFERER, $ref);
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
$html = curl_exec($ch);
curl_close($ch);
}
else{
$hfile = fopen($url,"r");
if($hfile){
while(!feof($hfile)){
$html.=fgets($hfile,1024);
}
}
}
return $html;
}
는 "사이트에 링크가 상대 링크가 될 수 있습니다." realpath() 함수는 이것이 내가 생각하는대로 풀어야한다. 예? – Vordreller
아니요, 경로가 원격 HTTP 경로이고 realpath()가 로컬 경로를 보여주기 때문입니다. –