PHP: Get the contents of a web page, RSS feed, or XML file into a string variable PHP: Get nội dung của một trang web, tin RSS, hoặc tệp tin XML vào một biến string
You will often have the need to access data that resides on another server, whether you are writing an online RSS aggregator or doing screen scraping for a searching mechanism. Bạn sẽ thường có nhu cầu truy cập dữ liệu mà nằm trên máy chủ khác, cho dù bạn đang viết một aggregator RSS trực tuyến hoặc làm màn hình cào cho một cơ chế tìm kiếm. PHP makes pulling this data into a string variable an extremely simple process. PHP làm kéo dữ liệu này vào một chuỗi biến một quá trình rất đơn giản.
You can go with the really short method: Bạn có thể đi với các phương pháp thực sự ngắn hạn:
$url = “http://www.howtogeek.com”; $ url = "http://www.howtogeek.com";
$str = file_get_contents($url); $ str = file_get_contents ($ url);
The only problem with that method is that some web hosts have url access blocked in the file methods, for security reasons. Vấn đề duy nhất với phương pháp đó là một số máy chủ web có url bị chặn truy cập vào các phương pháp tập tin, vì lý do an ninh. You may be able to use this workaround method instead: Bạn có thể sử dụng phương pháp này workaround thay vì:
function get_url_contents($url){ chức năng get_url_contents ($ url) ( $crl = curl_init(); $ CRL = curl_init (); $timeout = 5; $ timeout = 5; curl_setopt ($crl, CURLOPT_URL,$url); curl_setopt ($ CRL, CURLOPT_URL, $ url); curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ CRL, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt ($ CRL, CURLOPT_CONNECTTIMEOUT, $ timeout); $ret = curl_exec($crl); $ ret = curl_exec ($ CRL); curl_close($crl); curl_close ($ CRL); return $ret; return $ ret; } )
You should now have the contents of the website in a string variable. Bây giờ bạn có các nội dung của các trang web trong một biến chuỗi. Note that this doesn't pull down the supporting files such as javascript or CSS. Lưu ý rằng điều này không kéo xuống các tập tin hỗ trợ như javascript hay CSS. You will have to further parse the page and retrieve those seperately if you need the whole thing. Bạn sẽ phải tiếp tục phân tích các trang và lấy lại những cách riêng biệt nếu bạn cần toàn bộ điều.

Daily Email Updates Email cập nhật hàng ngày
You can get our how-to articles in your inbox each day for free. Bạn có thể làm thế nào chúng tôi vào các bài viết trong hộp thư của bạn mỗi ngày miễn phí. Just enter your name and email below: Chỉ cần nhập tên và email của bạn dưới đây:



Problem with RSS Feed in WordPress. Vấn đề với RSS trong WordPress.
I have a subdomain that I installed wordpress for another blog site, but the subdomain site's rss feed points to my parent site. Tôi có một tên miền phụ mà tôi đã cài đặt wordpress cho một trang blog, nhưng rss trang web tên miền phụ của thức ăn điểm đến trang web của mẹ tôi.
Can anyone come up with any suggestions? Bất cứ ai có thể đến với bất kỳ lời đề nghị?
Hi, Chào,
I've tried your hack but I always get the same result: Tôi đã thử hack của bạn nhưng tôi luôn nhận được cùng một kết quả:
“Destination host forbidden” "Điểm đến máy chủ lưu trữ cấm"
How can I solve this issue? Làm thế nào tôi có thể giải quyết vấn đề này?
Thanks. Cảm ơn.
Thanks a lot for your simple function. Cảm ơn rất nhiều cho chức năng đơn giản của bạn. This really gives a lot of power to user to reuse the internet! Điều này thực sự mang đến cho rất nhiều sức mạnh để người sử dụng để tái sử dụng internet!
Ofcourse the content should be pulled with prior approval! Ofcourse nội dung cần được kéo với chấp thuận trước!
i love u! i love u!