» »

[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

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

r5r ::

Rešitev: http://si2.php.net/manual/en/function.fsockopen.php

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.

NeOman ::

kul jaka, hvala. ti positnarim se kej preko IMinga ;)


Vredno ogleda ...

TemaSporočilaOglediZadnje sporočilo
TemaSporočilaOglediZadnje sporočilo
»

php send data to private dir

Oddelek: Programiranje
5836 (575) Excavator
»

PHP - Prenos priponk iz RSS vira

Oddelek: Programiranje
5537 (460) keworkian
»

PHP & XAMPP file_get_contents

Oddelek: Izdelava spletišč
151302 (1082) KoMar-
»

[php] Kako odstraniti dolocen text

Oddelek: Izdelava spletišč
51016 (957) rokpok
»

Kako z VS.NET priti do izvorne kode neke html strani?

Oddelek: Programiranje
91273 (1068) Microsoft

Več podobnih tem