Forum » Programiranje » [php] branje vsebin in prikaz
[php] branje vsebin in prikaz
NeOman ::
ubistvu imam problem z branjem vsebin na neki strani, zanima me kako bi lahko npr. iz tecajne liste prebral podatke ki jih stran prikaze in jih uporabil na neki svoji strani? ima kdo izkusnej s tem, kaksen namig bi bil dobrodosel.
lp
lp
Kami ::
Uporabiš file_get_contents da prebereš stran pol pa s pomočjo regular expressions pobereš ven tiste podatke ko rabiš.
NeOman ::
ok, hvala.
sicer dobim: Warning: file_get_contents(): URL file-access is disabled in the server configuration, mi je pa princip vsec. preden grem config spreminjat bi uprasu, ce obstajajo kaksne alternative za file_get_contents in ali se odprejo kaksne luknje na strezniku ce omogocim URL file-access?
lp
sicer dobim: Warning: file_get_contents(): URL file-access is disabled in the server configuration, mi je pa princip vsec. preden grem config spreminjat bi uprasu, ce obstajajo kaksne alternative za file_get_contents in ali se odprejo kaksne luknje na strezniku ce omogocim URL file-access?
lp
r5r ::
Rešitev: http://si2.php.net/manual/en/function.fsockopen.php
Grem poiskat, če imam kaj uporabnejšega na disku.
Grem poiskat, če imam kaj uporabnejšega na disku.
And it makes me wonder.
r5r ::
<?php error_reporting(0); $r = new HTTPRequest('http://example.com/file.txt'); $out = $r->DownloadToString(); if ($out!=='1') {echo $out;} else {echo 'Connection error!';} class HTTPRequest { var $_fp; // HTTP socket var $_url; // full URL var $_host; // HTTP host var $_protocol; // protocol (HTTP/HTTPS) var $_uri; // request URI var $_port; // port function _scan_url() { $req = $this->_url; $pos = strpos($req, '://'); $this->_protocol = strtolower(substr($req, 0, $pos)); $req = substr($req, $pos+3); $pos = strpos($req, '/'); if($pos === false) $pos = strlen($req); $host = substr($req, 0, $pos); if(strpos($host, ':') !== false) { list($this->_host, $this->_port) = explode(':', $host); } else { $this->_host = $host; $this->_port = ($this->_protocol == 'https') ? 443 : 80; } $this->_uri = substr($req, $pos); if($this->_uri == '') $this->_uri = '/'; } // constructor function HTTPRequest($url) { $this->_url = $url; $this->_scan_url(); } // download URL to string function DownloadToString() { $crlf = "\r\n"; // generate request $req = 'GET ' . $this->_uri . ' HTTP/1.0' . $crlf . 'Host: ' . $this->_host . $crlf . $crlf; // fetch if ($this->_fp = fsockopen(($this->_protocol == 'https' ? 'ssl://' : '') . $this->_host, $this->_port)) { fwrite($this->_fp, $req); while(is_resource($this->_fp) && $this->_fp && !feof($this->_fp)) $response .= fread($this->_fp, 1024); fclose($this->_fp); // split header and body $pos = strpos($response, $crlf . $crlf); if($pos === false) return($response); $header = substr($response, 0, $pos); $body = substr($response, $pos + 2 * strlen($crlf)); // parse headers $headers = array(); $lines = explode($crlf, $header); foreach($lines as $line) if(($pos = strpos($line, ':')) !== false) $headers[strtolower(trim(substr($line, 0, $pos)))] = trim(substr($line, $pos+1)); // redirection? if(isset($headers['location'])) { $http = new HTTPRequest($headers['location']); return($http->DownloadToString($http)); } else { return($body); } }else { return ('1'); } } } ?>
And it makes me wonder.
Vredno ogleda ...
Tema | Ogledi | Zadnje sporočilo | |
---|---|---|---|
Tema | Ogledi | Zadnje sporočilo | |
» | php send data to private dirOddelek: Programiranje | 904 (643) | Excavator |
» | PHP - Prenos priponk iz RSS viraOddelek: Programiranje | 611 (534) | keworkian |
» | PHP & XAMPP file_get_contentsOddelek: Izdelava spletišč | 1378 (1158) | KoMar- |
» | [php] Kako odstraniti dolocen textOddelek: Izdelava spletišč | 1094 (1035) | rokpok |
» | Kako z VS.NET priti do izvorne kode neke html strani?Oddelek: Programiranje | 1355 (1150) | Microsoft |