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 obsahu webovej stránky, RSS feed alebo XML súboru do premennej reťazca

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. Budete často potrebujú prístup k dátam, ktorá je umiestnená na inom serveri, či už píšete online RSS agregátor aneb obrazovku škrabkou na vyhľadávanie mechanizmus. PHP makes pulling this data into a string variable an extremely simple process. PHP je ťahanie tieto dáta do reťazca premennej veľmi jednoduchý proces.

You can go with the really short method: Môžete ísť s veľmi krátkou metódy:

$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. Jediný problém s touto metódou je, že niektoré webové hostí sa url prístup zablokovaný v súbore metód, z bezpečnostných dôvodov. You may be able to use this workaround method instead: Môžete byť schopní používať túto metódu riešenia miesto:

 function get_url_contents($url){ Funkcia 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. Teraz by ste mali mať obsah týchto stránok v premennej reťazca. Note that this doesn't pull down the supporting files such as javascript or CSS. Všimnite si, že to nie je strhnúť podporné súbory, ako sú JavaScript alebo CSS. You will have to further parse the page and retrieve those seperately if you need the whole thing. Budete musieť ďalej analyzovať a načítanie stránky sú zvlášť, ak budete potrebovať celú vec.

This article was originally written on 09/25/06 Tagged with: Tento článok bol pôvodne napísaný na 09/25/06 Tagged s: PHP PHP , , Programming Programovanie

Daily Email Updates Denný Svářeč

You can get our how-to articles in your inbox each day for free. Môžete si naše jak-na články vo vašej schránky každý deň zadarmo. Just enter your name and email below: Stačí zadať svoje meno a e-mail nižšie:


Name: Meno:
Email: E-mail:

Comments (4) Komentáre (4)

  1. Demetrius Demetrius

    Problem with RSS Feed in WordPress. Problém s RSS feed do 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. Mám subdomény, ktoré som wordpress nainštalovaný na inom blogu, ale subdomény webových stránok RSS feed poukazuje na mojej nadradeného webe.
    Can anyone come up with any suggestions? Môže niekto prísť s návrhmi?

  2. Davide Davide

    Hi, Nazdar,

    I've tried your hack but I always get the same result: Snažil som sa zaseknúť, ale ja si vždy rovnaký výsledok:

    “Destination host forbidden” "Destination zakázané host"

    How can I solve this issue? Ako môžem tento problém vyriešiť?

    Thanks. Vďaka.

  3. ypi prem ypi Prem

    Thanks a lot for your simple function. Díky moc za vaše jednoduché funkcie. This really gives a lot of power to user to reuse the internet! Tento fakt dáva veľa sily, aby používateľ opätovne použiť internet!
    Ofcourse the content should be pulled with prior approval! Samozrejme obsah by mal byť vytiahol s predchádzajúcim súhlasom!

  4. anonymous anonymný

    i love u! i love u!


Leave a Comment Zanechať komentár




Leave your Zanechajte svoj friendly priateľský comment here. komentár tu.

If you have a computer help question, Ak máte počítač pomôže otázku, click here to leave it on the forums kliknite tu nechať to na fórach instead. miesto.

Note: Your comment may not show up immediately on the site. Poznámka: Váš komentár sa nezobrazia okamžite na mieste.

Our Friends Naši priatelia
Getting Started Začíname


About How-To Geek O tom, ako-To Geek
What Is That Process? Čo je to za proces?
svchost.exe svchost.exe
jusched.exe jusched.exe
dwm.exe Dwm.exe
ctfmon.exe ctfmon.exe
wmpnetwk.exe wmpnetwk.exe
mDNSResponder.exe mDNSResponder.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.