Đây là hai khác nhau, cách đơn giản để có được nội dung từ URL:
1) phương pháp đầu tiên
Enable allow_url_include từ lưu trữ (php của bạn.ini hoặc một nơi nào)
<?php
$variableee = readfile("http://example.com/");
echo $variableee;
?>
hoặc
2) Phương pháp thứ hai
Enable php_curl, php_imap và php_openssl
<?php
// you can add anoother curl options too
// see here - http://php.net/manual/en/function.curl-setopt.php
function get_dataa($url) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$variableee = get_dataa('http://example.com');
echo $variableee;
?>
Nguồn
2013-04-03 13:36:44
Bạn có thể giải thích thêm về điều này không. Bạn muốn gửi yêu cầu web đến URL đã cho và đọc câu trả lời cho Biến tôi đoán? –
Vâng, cùng một điều tôi muốn, tôi muốn toàn bộ mã nguồn trong một biến được trả về bởi yêu cầu web đó. – Prashant
Bạn có thể sử dụng [công cụ này] (http://codecanyon.net/item/javascript-web-scraper/8598806) để dễ dàng xóa html. –