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: Dabūt no tīmekļa lapas RSS feed saturu vai XML faila string mainīgā

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. Jūs bieži vien ir nepieciešamas, lai piekļūtu datiem, kas dzīvo uz citu serveri, vai jūs rakstāt tiešsaistē RSS aggregator vai darot ekrāns kasīšanas par meklēšanas mehānismu. PHP makes pulling this data into a string variable an extremely simple process. PHP padara vilkšanu šos datus ņem string mainīgais ļoti vienkāršs process.

You can go with the really short method: Varat doties ar ļoti īsu metodi:

$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. Vienīgā problēma ar šo metodi, ir tas, ka daži web hosts ir url piekļuve liegta failu metodes, drošības apsvērumu dēļ. You may be able to use this workaround method instead: Jūs varat izmantot šo PROFILAKSE metode vietā ir:

 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 ($ KRL CURLOPT_URL, $ url); 
         curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ KRL CURLOPT_RETURNTRANSFER, 1); 
         curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt ($ KRL CURLOPT_CONNECTTIMEOUT, $ timeout); 
         $ret = curl_exec($crl); $ ret = curl_exec ($ KRL); 
         curl_close($crl); curl_close ($ KRL); 
         return $ret; return $ ret; 
 } ) 

You should now have the contents of the website in a string variable. Jūs tagad ir no mājas lapas saturu string mainīgo. Note that this doesn't pull down the supporting files such as javascript or CSS. Ievērojiet, ka šī nav nojaukt atbalsta failus, piemēram, JavaScript vai CSS. You will have to further parse the page and retrieve those seperately if you need the whole thing. Jums būs vēl izanalizēt lapu un paņemt tās atsevišķi, ja jums nepieciešama visa lieta.

This article was originally written on 09/25/06 Tagged with: Šis pants tika sākotnēji rakstīts uz 09/25/06 tagged with: PHP PHP , , Programming Programmēšana

Daily Email Updates Daily Email Updates

You can get our how-to articles in your inbox each day for free. Jūs varat saņemt mūsu how-to rakstus savā pastkastītē katru dienu par brīvu. Just enter your name and email below: Vienkārši ievadiet jūsu vārdu un e-pasta zemāk:


Name: Vārds:
Email: E-pasts:

Comments (4) Komentāri (4)

  1. Demetrius Demetrius

    Problem with RSS Feed in WordPress. Problēma ar RSS Feed 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. Man ir apakšdomēns, ka es instal WordPress citu emuāru vietnē, bet apakšdomēna portāla RSS padeve norāda uz manu vecāku vietā.
    Can anyone come up with any suggestions? Can anyone nākt klajā ar kādi ieteikumi?

  2. Davide Davide

    Hi, Čau,

    I've tried your hack but I always get the same result: I've tried Jūsu kapāt, bet man vienmēr saņemsiet pašu rezultātu:

    “Destination host forbidden” "Destination uzņēmēja aizliegta"

    How can I solve this issue? Kā es varu atrisināt šo problēmu?

    Thanks. Pateicība.

  3. ypi prem ypi Prem

    Thanks a lot for your simple function. Thanks daudz par jūsu vienkāršu funkciju. This really gives a lot of power to user to reuse the internet! Tas patiešām dod daudz enerģijas lietotāju atkārtoti izmantot internetu!
    Ofcourse the content should be pulled with prior approval! Protams saturs būtu velk ar iepriekšēju apstiprinājumu!

  4. anonymous anonīms

    i love u! i love u!


Leave a Comment Leave Comment




Leave your Atstājiet savu friendly draudzīgs comment here. komentārus šeit.

If you have a computer help question, Ja Jums ir dators palīdzēt jautājumu, click here to leave it on the forums click here to atstāt uz forumu instead. vietā.

Note: Your comment may not show up immediately on the site. Piezīme: Jūsu komentārs var neparādīties pat tieši uz vietas.

Our Friends Our Friends
Getting Started Getting Started


About How-To Geek Par How-To Geek
What Is That Process? Kas ir šis process?
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.