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.

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:



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?
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.
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!
i love u! i love u!