[Variablen] Zufälliger Url einer Seite

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • [Variablen] Zufälliger Url einer Seite

    Hallo,

    Ich suche ein Script, welches mir einen zufälligen URL (von einem Link) auf einer Seite aussucht und in eine beliebige Variable schreibt.

    Nehmen wir mal an die Seite hat 100 Links. Bei jedem aufruf soll halt je nach Zufallsprinzig ein anderer URL aus einem Link ausgelesen werden.

    Die Seite wird mit file() aufgerufen.

    Danke schonmal

  • #2
    und *move*

    Kommentar


    • #3
      Also gut, da noch keiner geantwortet hat (außer dem lieben Moderator :P), beschreib ich meine Vorstellung hier mal etwas genauer.

      Das bisherige Script liest eine Beliebige Seite aus, und speichert sie in eine Variable (Array wäre auch möglich).

      Der Inhalt der Variable sieht dann z.B. so aus:

      PHP-Code:
      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
      <
      html>

      <
      head>
      <
      style>
      a:link            {font:8pt/11pt verdanacolor:red}
      a:visited        {font:8pt/11pt verdanacolor:#4e4e4e}
      </style>
      <
      meta HTTP-EQUIV="Content-Type" Content="text-html; charset=Windows-1252">
      <
      title>Keine Seite zum Anzeigen </title>
      </
      head>

      <
      body bgcolor="white">

      <
      table width="400" cellpadding="3" cellspacing="5">
        <
      tr>
          <
      td id="tableProps" valign="top" align="left"><a href="http://www.bla.de/?sdaad=asda&asdas=asa" target="blank">LINK</a><br>
          <
      a target="top" href="index.php?seite=2">SEITE 2</a><br>
          <
      a href="./index.php?seite=3">index.php?seite=3</a><br><a target="top" href="www.google.de">Google</a>
          </
      td>
        </
      tr>
      </
      table>
      </
      body>
      </
      html
      Und er soll mir alle Links die in <a>-Tags stehen in einen Array schreiben, egal ob der Link im Format "./index.php?seite=3", "www.google.de", oder "http://www.bla.de/?sdaad=asda&asdas=asa" ist.

      Danke

      Kommentar


      • #4
        quick 'n' dirty:
        PHP-Code:
        <?php
        $html 
        file_get_contents('http://www.google.com/');
        preg_match_all('/<a.*<\/a>/iU'$html$matches);
        shuffle($matches[0]);
        echo 
        $matches[0][0];
        ?>
        bush

        EDIT:

        das board schluckt einen backslash! die zeile richtig:
        Code:
        preg_match_all('/<a.*<\/a>/iU', $html, $matches);

        Zuletzt geändert von Bushmasta; 23.04.2006, 23:50.

        Kommentar


        • #5
          Original geschrieben von Bushmasta
          quick 'n' dirty:
          PHP-Code:
          <?php
          $html 
          file_get_contents('http://www.google.com/');
          preg_match_all('/<a.*<\/a>/iU'$html$matches);
          shuffle($matches[0]);
          echo 
          $matches[0][0];
          ?>
          bush
          Danke!
          Funktioniert perfekt.
          Ich wollte aber das der URL (ohne dem <a...>...</a>), also das was im href= steht angezeigt haben. Geht das?

          Kommentar


          • #6
            So habs mitlerweile selber rausgefunden, hier gleich mal ein kleines Script: ^^

            PHP-Code:
            <?php

            // [url]http://www.php-resource.de/forum/showthread.php?s=&threadid=69524[/url]

            echo "<html>
            <head>
            <title>Linkfinder</title>
            </head>

            <body>"
            ;

            if (isset(
            $HTTP_POST_VARS['link'])) {
               
            $html file_get_contents($HTTP_POST_VARS['link']);
               
            preg_match_all("/<a.*<\/a>/iU"$html$matches);
               
            shuffle($matches[0]);
               
            preg_match("/<a.*?href=(\"|'|)([^\(\"|'|>| )]*)(\"|'|| )[^>]*>([^<]*)<\/a>/is"$matches[0][0], $matches1);
               echo 
            "Zuf&auml;lliger Link:<br>
            "
            .$matches1[2]."<br>
            <br>"
            ;
            }

            echo 
            "<form action='".$PHP_SELF."' method='post'>
            <h2>Linkfinder mit Zufallsprinzip</h2>
            <br>
            <input type='text' name='link' value='"
            .$HTTP_POST_VARS['link']."'><br>
            <br>
            <input type='submit' name='sumbit' value='Durchsuchen'>
            </form>
            </body>
            </html>"
            ;

            ?>
            Viel Spaß
            Zuletzt geändert von Reiser; 23.04.2006, 22:34.

            Kommentar

            Lädt...
            X