적절한 URL과 빠른 알고리즘 점점 : 등 https://example.org 대신 빠른 알고리즘을 무엇PHP, 내가 적절한 URL을 취득하기위한 기능이
function startsWith($haystack, $needle) {
return !strncmp($haystack, $needle, strlen($needle));
}
function properUrl($url) {
$urls = array();
if (startsWith($url, "https://") || startsWith($url, "http://")) {
$urls[] = $url;
} else if (startsWith($url, "www.")) {
$url = substr($url, 4);
$urls[] = "http://$url";
$urls[] = "http://www.$url";
$urls[] = "https://$url";
$urls[] = "https://www.$url";
} else {
$urls[] = "http://$url";
$urls[] = "http://www.$url";
$urls[] = "https://$url";
$urls[] = "https://www.$url";
}
foreach ($urls as $u) {
if (@file_get_contents($u)) {
$url = $u;
break;
}
}
return $url;
}
에 http://example.com에 example.com을 www.example.org을 file_get_contents 중. 나는 적당한 URL을 얻고 싶다. 전체 페이지를 읽지는 마라. 감사.
기술적으로 'http : // www.example.org /'와 'http : // example.org /'는 전혀 다른 두 개의 서로 관련이없는 URL이므로 두 가지 중 어느 것이 맞는지 추측 할 수 없습니다. * 두 * 모두 정확합니까? – Jon