Important! This is an automatic machine translated page. If you can read english, you should Click Here to read the original English version of the article.

PHP: Get the contents of a web page, RSS feed, or XML file into a string variable PHP: Dapatkan isi dari suatu halaman web, RSS feed, atau file XML ke dalam sebuah variabel 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. Anda akan sering memiliki kebutuhan untuk mengakses data yang berada di server lain, apakah Anda sedang menulis sebuah online RSS agregator atau melakukan menggores layar untuk mencari mekanisme. PHP makes pulling this data into a string variable an extremely simple process. PHP membuat menarik data ini ke dalam sebuah string variabel proses yang sangat sederhana.

You can go with the really short method: Anda dapat pergi dengan metode yang benar-benar pendek:

$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. Satu-satunya masalah dengan metode tersebut adalah bahwa beberapa web host memiliki akses url file diblokir di metode, untuk alasan keamanan. You may be able to use this workaround method instead: Anda mungkin dapat menggunakan metode prosedur ini sebagai gantinya:

 function get_url_contents($url){ fungsi 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. Anda seharusnya sudah memiliki isi website dalam variabel string. Note that this doesn't pull down the supporting files such as javascript or CSS. Catatan bahwa ini tidak pull down file pendukung seperti javascript atau CSS. You will have to further parse the page and retrieve those seperately if you need the whole thing. Anda akan harus mengurai lebih lanjut halaman dan mengambil orang-orang secara terpisah jika Anda memerlukan semuanya.

This article was originally written on 09/25/06 Tagged with: Artikel ini awalnya ditulis pada 09/25/06 Tagged with: PHP PHP , , Programming Pemrograman

Daily Email Updates Harian Email Pembaharuan

You can get our how-to articles in your inbox each day for free. Anda bisa mendapatkan kita bagaimana-untuk artikel dalam kotak masuk Anda setiap hari secara gratis. Just enter your name and email below: Cukup masukkan nama dan email Anda di bawah ini:


Name: Nama:
Email: Email:

Comments (4) Komentar (4)

  1. Demetrius Demetrius

    Problem with RSS Feed in WordPress. Masalah dengan RSS Feed di 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. Aku punya subdomain yang saya diinstal wordpress untuk situs blog lain, tetapi situs subdomain poin rss feed ke situs induk.
    Can anyone come up with any suggestions? Can anyone datang dengan saran-saran?

  2. Davide Davide

    Hi, Hai,

    I've tried your hack but I always get the same result: Saya sudah mencoba hack Anda tetapi saya selalu mendapatkan hasil yang sama:

    “Destination host forbidden” "Tujuan host dilarang"

    How can I solve this issue? Bagaimana saya bisa memecahkan masalah ini?

    Thanks. Terima kasih.

  3. ypi prem YPI Prem

    Thanks a lot for your simple function. Thanks a lot untuk fungsi sederhana. This really gives a lot of power to user to reuse the internet! Ini benar-benar memberikan banyak kekuatan untuk pengguna untuk menggunakan kembali internet!
    Ofcourse the content should be pulled with prior approval! Ofcourse konten harus ditarik dengan persetujuan terlebih dulu!

  4. anonymous anonim

    i love u! i love u!


Leave a Comment Tinggalkan Komentar




Leave your Meninggalkan friendly ramah comment here. komentar di sini.

If you have a computer help question, Jika Anda memiliki pertanyaan bantuan komputer, click here to leave it on the forums klik di sini untuk meninggalkannya di forum instead. selain.

Note: Your comment may not show up immediately on the site. Catatan: Komentar anda mungkin tidak muncul segera di situs.

Our Friends Our Friends
Getting Started Persiapan


About How-To Geek Tentang How-To Geek
What Is That Process? Apa Proses Itu?
svchost.exe svchost.exe
jusched.exe jusched.exe
dwm.exe dwm.exe
ctfmon.exe ctfmon.exe
wmpnetwk.exe wmpnetwk.exe
wmpnscfg.exe wmpnscfg.exe
rundll32.exe rundll32.exe
wfcrun32.exe wfcrun32.exe
Ipoint.exe Ipoint.exe
Itype.exe Itype.exe
Wfica32.exe Wfica32.exe
Mobsync.exe Mobsync.exe
conhost.exe conhost.exe
Dpupdchk.exe Dpupdchk.exe Adobe_Updater.exe Adobe_Updater.exe

Copyright © 2006-2009 HowToGeek.com. Copyright © 2006-2009 HowToGeek.com. All Rights Reserved. All Rights Reserved.