Źródło:


Komentarze (0)


Ocena:
0

źródło pochodzi od: admin

Opis:
Funkcja wstawiająca na stronę wybraną zawartość z innego url-a: podajemy url, element (string) od którego zaczynamy operację i element na którym kończymy. Ryzykowne jeśli posiadacz url-a zacznie hotlinkować swoją stronę...

Język: php


<?php

  function addBase( $baseUrl, $code )
  {
        // This is a very naive implementation, it doesn't properly

        // parse the "img" tag, but only looks for the string

        // '<img src="' - if the 'src' element comes somewhere else

        // within the tag, or if the filename it points to isn't

        // in double-quotes, this routine won't catch it.

        // Also this routine is chock full of magic numbers.  Whooop.

    $pCode = $code; $index = 0;
    while( $index < strlen( $code ) )
    {
      $srcPos = strpos( $pCode, "<img src="", $index );
      if( $srcPos != false )
      {
        // check for a ":" in the first 7 characters after 'src=', in which

        // case it's already a URL

        $colonStr = strpos( $pCode, ":", $srcPos );
        $subStrLen = $srcPos + 10 - $index; // 10 = size of "<img src="" string.

        echo( substr( $pCode, $index, $subStrLen) );
        $index += $subStrLen;
        if( ($colonStr < 12) || ($colonStr > 16) || ($colonStr === false) )
            // somewhat arbitrary

        {
          // modify the string by adding the $baseUrl

          echo( $baseUrl );
        }
      }
      else
      {
        $subStrLen = strlen( $code ) - $index;
        echo( substr( $pCode, $index, $subStrLen) );
        $index = strlen( $code );
      }
    }
  }

  function report( $message, $report )
  {
    if( $report != FALSE )
      echo( $message );
  }

  function includeFrom( $fromUrl, $baseUrl, $startString, $endString, $report )
  // $fromUrl - URL to read from, e.g. "http://foo.bar.com/index.html"

  // $baseUrl - Base to apply to local resources, e.g. "http://foo.bar.com/"

  // $startString - String before content you want to include

  // $endString - String after content you want to include

  // $report - "FALSE" if you don't want includeFrom() to insert error

  //          reporting into the output; errors will just cause no output

  {
    $fd = fopen( $fromUrl, "r" );
    if( $fd != FALSE )
    {
      $fr = fread( fopen( $fromUrl, "r" ), 100000 );
      fclose( $fd );
       
      if ($fr) {
        $start = strpos( $fr, $startString ) + strlen($startString);
        $finish = strpos( $fr, $endString ); // - strlen($endString);

        if( ($start != FALSE) && ($finish != FALSE) )
        {
          $length = $finish - $start;
          $code = Substr( $fr, $start, $length );
// if you don't want to get fancy, use echo( $code ) instead of addBase()

          addBase( $baseUrl, $code );
        }
        else
          report( "<! delimiter not found in $fromUrl >", $report );
      }
      else
        report( "<! could not read data from $fromUrl >", $report );
    }
    else
      report( "<! could not open $fromUrl >", $report );
  }

// Below here is just test code...

?>
<html>
<body>
<?php
  includeFrom( "http://www.sfgate.com/weather/",
              "http://www.sfgate.com",
              "<!-- begin 5day forecast -->",
              "<!-- end 5day forecast -->",
              TRUE );
?>
</body>
</html>
</body>
</html>
powrót

Tagi do źródła:
Pobieranie zawartości strony, html, php


Nikt jeszcze nie skomentował tego źródła.


assembler baza danych bot c crawler delphi html java kontakt box loader mail obsługa sieci obsługa zapyt(..) own os php pop3 porównywanie (..) przeszukiwanie(..) robot sieciowy rozmowa symulator rozm(..) system operacy(..) voteban stop wysyłanie e-m(..) boot dekodowanie mim(..) java juzef kolejny skrypt (..) mysql pobieranie zawa(..) przeglądanie e(..) sdl whois wysyłanie e-ma(..)

Wszystkie...


sources.pl to strona przeznaczona dla programistów, początkujących programistów i zupełnych amatorów programowania. Tu możesz umieścić swój kod, program napisany przez Ciebie, lub po prostu skomentować kod innego programisty.

Szukaj:


Źródeł: 30, oczekujących: 3, odrzuconych: 11

O stronie | kontakt |

Sources.pl

Ilość wejść: dzisiaj - 27 (unikalne: 27), ogółem - 687103 (unikalne: 612105)