URL PHP에서 임의의 데이터를 어떻게로드합니까?
문제
이 질문은 간단합니다. PHP 스크립트에서 어떤 기능을 사용하여 URL에서 데이터를 문자열로로드합니까?
해결책
컬은 일반적으로 좋은 해결책입니다. http://www.php.net/curl
// create a new cURL resource
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// grab URL and pass it to the browser
$html = curl_exec($ch);
// close cURL resource, and free up system resources
curl_close($ch);
다른 팁
나는 당신이 찾고 있다고 생각합니다
$url_data = file_get_contents("http://example.com/examplefile.txt");
파일 포장지를 사용하면 file_get_contents를 사용하여 HTTP 리소스에 액세스 할 수 있습니다 (거의 요청을받지 못합니다. 게시물 없음). 보다 복잡한 HTTP 요청을 위해서는 컬 포장지를 설치 한 경우 컬 랩퍼를 사용할 수 있습니다. 자세한 내용은 php.net을 확인하십시오.
체크 아웃 스누피, 웹 브라우저를 시뮬레이션하는 PHP 클래스 :
include "Snoopy.class.php";
$snoopy = new Snoopy;
$snoopy->fetchtext("http://www.example.com");
$html = $snoopy->results;
제휴하지 않습니다 StackOverflow