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: Get vsebine spletne strani, RSS, ali XML datoteke v string spremenljivko

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. Boste pogosto potrebujete dostop do podatkov, ki stalno prebiva na drugem strežniku, ali pišete na spletu zbiralnik RSS ali "Narediti zaslon strganje za iskanje mehanizma. PHP makes pulling this data into a string variable an extremely simple process. PHP omogoča vlečenje te podatke v spremenljivke niz izjemno preprost proces.

You can go with the really short method: Lahko greš z zares kratko metoda:

$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. Edini problem s to metodo je, da nekateri spletni gostitelji imajo blokiran dostop url v datoteki metod, zaradi varnostnih razlogov. You may be able to use this workaround method instead: Morda boste lahko uporabljali to rešitev metodo namesto:

 function get_url_contents($url){ Funkcija get_url_contents ($ url) ( 
         $crl = curl_init(); $ = CRL curl_init (); 
         $timeout = 5; $ timeout = 5; 
         curl_setopt ($crl, CURLOPT_URL,$url); curl_setopt ($ RLS, CURLOPT_URL, $ url); 
         curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ RLS, CURLOPT_RETURNTRANSFER, 1); 
         curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt ($ RLS, 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. Zdaj bi morali imeti vsebino spletne strani v nizu spremenljivke. Note that this doesn't pull down the supporting files such as javascript or CSS. Upoštevajte, da to ne podirajo podporne datoteke, kot so javascript in CSS. You will have to further parse the page and retrieve those seperately if you need the whole thing. Imeli boste dodatno razčleniti stran in pridobivanje tistih ločeno, če boste potrebovali vso stvar.

This article was originally written on 09/25/06 Tagged with: Ta članek je bil prvotno napisan na 09/25/06 Tagged with: PHP PHP , , Programming Programming

Daily Email Updates Dnevni Email Updates

You can get our how-to articles in your inbox each day for free. Lahko dobite našo kako do člankov v vašo mapo »Prejeto vsak dan brezplačno. Just enter your name and email below: Preprosto vpišite vaše ime in e-pošto spodaj:


Name: Ime:
Email: E-pošta:

Comments (4) Komentarji (4)

  1. Demetrius Demetrius

    Problem with RSS Feed in WordPress. Težava z RSS Feed v 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. Imam poddomeno, da sem namestil wordpress blog za drugo mesto, vendar poddomene spletnega mesta rss feed točk na svoj nadrejenega mesta.
    Can anyone come up with any suggestions? Lahko kdo prišel gor s kakršnimi koli predlogi?

  2. Davide Davide

    Hi, Živjo,

    I've tried your hack but I always get the same result: Ive 'preizkušen vaš kramp vendar sem vedno dobil enak rezultat:

    “Destination host forbidden” "Destination prepovedana host"

    How can I solve this issue? Kako rešiti to vprašanje?

    Thanks. Hvala.

  3. ypi prem ypi Prem

    Thanks a lot for your simple function. Hvala veliko zakaj vaš enostavno delovanje. This really gives a lot of power to user to reuse the internet! To res daje veliko moči, da uporabnik ponovno internet!
    Ofcourse the content should be pulled with prior approval! Seveda vsebino je treba izvleči s predhodno odobritvijo!

  4. anonymous anonymous

    i love u! i love u!


Leave a Comment Pustite komentar




Leave your Pustite friendly prijazen comment here. comment here.

If you have a computer help question, Če imate računalnik pomagati vprašanje, click here to leave it on the forums kliknite tukaj, da ga pustijo na forumih instead. namesto.

Note: Your comment may not show up immediately on the site. Opomba: Tvoj komentar morda ne pokažejo takoj na mestu.

Our Friends Naši prijatelji
Getting Started Getting Started


About How-To Geek O Kako naj Geek
What Is That Process? Kaj je to proces?
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.