내가 "http://example.com/test.html에서 파일에 링크"example.com "을 찾고 말할 수 있습니다 ..하고 싶은 것입니다 확인
내가 원하는. 언급 된 웹 사이트에서를 찾는 PHP 스크립트를 사용합니다. 그러나 클래스 나 ID 태그가있는 경우에도 작동해야합니다.
내가 "http://example.com/test.html에서 파일에 링크"example.com "을 찾고 말할 수 있습니다 ..하고 싶은 것입니다 확인
내가 원하는. 언급 된 웹 사이트에서를 찾는 PHP 스크립트를 사용합니다. 그러나 클래스 나 ID 태그가있는 경우에도 작동해야합니다.
는
How can I check if a URL exists via PHP?
또는 그것을
$file = 'http://www.domain.com/somefile.jpg';
$file_headers = @get_headers($file);
if($file_headers[0] == 'HTTP/1.1 404 Not Found') {
$exists = false;
}
else {
$exists = true;
}
여기에서 시도 URL을 아래 참조 : http://www.php.net/manual/en/function.file-exists.php#75064
... 오른쪽 위의 포스트 아래, 컬 해결 방법이 있습니다 :
function url_exists($url) {
if (!$fp = curl_init($url)) return false;
return true;
}
업데이트 코드 : -
은 아래 URL을 참조 당신은 태그 찾기 ID 또는 클래스 SimpleHtmlDom 클래스를 사용할 수 있습니다
http://simplehtmldom.sourceforge.net/
http://simplehtmldom.sourceforge.net/manual_api.htm
다른 사람이 필요로하는 경우에 여기 있습니다. 또한
$url = "http://example.com/test.html";
$searchFor = "example.com"
$input = @file_get_contents($url) or die("Could not access file: $url");
$regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>";
if(preg_match_all("/$regexp/siU", $input, $matches, PREG_SET_ORDER)) {
foreach($matches as $match) {
echo $match[2];
if ($match[2] == $searchFor)
{
$isMatch = 1;
} else {
$isMatch= 0;
}
// $match[0] = A tag
// $match[2] = link address
// $match[3] = link text
}
}
if ($isMatch)
{
echo "<p><font color=red size=5 align=center>The page specified does contain your link. You have been credited the award amount!</font></p>";
} else {
echo "<p><font color=red size=5 align=center>The specified page does not have your referral link.</font></p>";
}
[그는 조랑말 ....] (http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454) – Tchoupi
무엇을 연결 시간 초과 (- 코드), 403 및 301에 대해? 더 나은 방법은 HTTP 응답 코드를 확인하는 것이 200이라고 생각합니까? 허위 사실. –
URL이 있는지 확인하지 못했습니다. 에있는 HREF가 "Example.com"과 같은지 확인하는 것이 었습니다. – alexander7567
업데이트 답변을 참조하십시오. –