Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 11

Discussione: Problema con array

  1. #1

    Problema con array

    Salve a tutti,

    ho un problema per quanto riguarda la gestione di un array.

    Nel mio codice recupero da una pagina web il codice sorgente con file_get_html, questo lo passo con

    Codice PHP:
    preg_match_all($regex_pattern$theData$links)) 
    per estrapolare dei links.

    Se ottengo un solo risultato non ho problemi:

    Codice PHP:
    echo $links[0
    mi restituisce il contenuto corretto.

    Ma se, invece, ci sono più risultati, non so più come fare a visualizzarli tutti.

    Grazie

  2. #2
    Ciao,

    prova
    Codice PHP:
    foreach ($links as $linksall) {
       echo 
    $linksall,'
    '
    ;
    }
    unset(
    $linksall); 
    Vedi qui
    http://forum.html.it/forum/showthrea...readid=1444368

  3. #3
    Non riesco a capire, ho provato con il ciclo foreach ma non riesco a ottenere ciò che ho bisogno.

    L'array che mi resistuisce preg_match_all è il seguente:

    codice:
    array(4) { [0]=> array(12) { [0]=> string(55) "https://rapidshare.com/files/3751374383/test.part1.rar"" [1]=> string(55) "https://rapidshare.com/files/3751374383/test.part1.rar"" [2]=> string(67) "https://rapidshare.com/files/3751374383/test.part1.rar
    string(55) "https://rapidshare.com/files/2630322117/test.part2.rar"" [4]=> string(55) "https://rapidshare.com/files/2630322117/test.part2.rar"" [5]=> string(67) "https://rapidshare.com/files/2630322117/test.part2.rar
    
    string(55) "https://rapidshare.com/files/3710037768/test.part3.rar"" [7]=> string(55) "https://rapidshare.com/files/3710037768/test.part3.rar"" [8]=> string(67) "https://rapidshare.com/files/3710037768/test.part3.rar
    
    string(55) "https://rapidshare.com/files/1095538876/test.part4.rar"" [10]=> string(55) "https://rapidshare.com/files/1095538876/test.part4.rar"" [11]=> string(68) "https://rapidshare.com/files/1095538876/test.part4.rar
    
    " } [1]=> array(12) { [0]=> string(5) "https" [1]=> string(5) "https" [2]=> string(5) "https" [3]=> string(5) "https" [4]=> string(5) "https" [5]=> string(5) "https" [6]=> string(5) "https" [7]=> string(5) "https" [8]=> string(5) "https" [9]=> string(5) "https" [10]=> string(5) "https" [11]=> string(5) "https" } [2]=> array(12) { [0]=> string(10) "3751374383" [1]=> string(10) "3751374383" [2]=> string(10) "3751374383" [3]=> string(10) "2630322117" [4]=> string(10) "2630322117" [5]=> string(10) "2630322117" [6]=> string(10) "3710037768" [7]=> string(10) "3710037768" [8]=> string(10) "3710037768" [9]=> string(10) "1095538876" [10]=> string(10) "1095538876" [11]=> string(10) "1095538876" } [3]=> array(12) { [0]=> string(15) "test.part1.rar"" [1]=> string(15) "test.part1.rar"" [2]=> string(27) "test.part1.rar
    string(15) "test.part2.rar"" [4]=> string(15) "test.part2.rar"" [5]=> string(27) "test.part2.rar
    
    string(15) "test.part3.rar"" [7]=> string(15) "test.part3.rar"" [8]=> string(27) "test.part3.rar
    
    string(15) "test.part4.rar"" [10]=> string(15) "test.part4.rar"" [11]=> string(28) "test.part4.rar
    Io ho bisogno di stampare i links completi..

  4. #4
    Ciao,

    mi sembra che l'array sia multidimensionale.

    Questo cosa ti dà?

    E cosa intendi per "link completo"?

    Soprattutto: qual è lo script che forma il tuo array?




    Edit: scusa script errato... chiedo venia...

  5. #5
    Originariamente inviato da MrsCassandra
    Ciao,

    mi sembra che l'array sia multidimensionale.

    Codice PHP:
    foreach ($links as $linksall) {
      foreach (
    $linksall as $sottolink) {
         echo 
    $sottolink,'
    '
    ;
      }
    }
    unset(
    $sottolink);
    unset(
    $linksall); 
    Questo cosa ti dà?

    E cosa intendi per "link completo"?

    Soprattutto: qual è lo script che forma il tuo array?


    Codice PHP:
    $regex_pattern '#(http|https):\/\/rapidshare\.com\/files\/(\d+)\/([^\s]+)#is';
    $theData $html;
    if(
    preg_match_all($regex_pattern$theData$links)) {
    print_r($links);
    //echo $links[2];

    $count count($links[0]);
    $links2 $links[0];
    echo 
    "[b]Number of Urls[/b] = " .$count."

    "
    ;
    for (
    $row 0$row $count $row++) {
    //print_r ($links);
    echo $links[0]["$row"]."
    "
    ;

    In questo modo l'array è cosi composto:

    codice:
    Array ( [0] => Array ( [0] => https://rapidshare.com/files/3751374383/test.part1.rar" [1] => https://rapidshare.com/files/3751374383/test.part1.rar" [2] => https://rapidshare.com/files/3751374383/test.part1.rar
    https://rapidshare.com/files/2630322117/test.part2.rar" [4] => https://rapidshare.com/files/2630322117/test.part2.rar" [5] => https://rapidshare.com/files/2630322117/test.part2.rar
    
    https://rapidshare.com/files/3710037768/test.part3.rar" [7] => https://rapidshare.com/files/3710037768/test.part3.rar" [8] => https://rapidshare.com/files/3710037768/test.part3.rar
    
    https://rapidshare.com/files/1095538876/test.part4.rar" [10] => https://rapidshare.com/files/1095538876/test.part4.rar" [11] => https://rapidshare.com/files/1095538876/test.part4.rar
    
    ) [1] => Array ( [0] => https [1] => https [2] => https [3] => https [4] => https [5] => https [6] => https [7] => https [8] => https [9] => https [10] => https [11] => https ) [2] => Array ( [0] => 3751374383 [1] => 3751374383 [2] => 3751374383 [3] => 2630322117 [4] => 2630322117 [5] => 2630322117 [6] => 3710037768 [7] => 3710037768 [8] => 3710037768 [9] => 1095538876 [10] => 1095538876 [11] => 1095538876 ) [3] => Array ( [0] => test.part1.rar" [1] => test.part1.rar" [2] => test.part1.rar
    test.part2.rar" [4] => test.part2.rar" [5] => test.part2.rar
    
    test.part3.rar" [7] => test.part3.rar" [8] => test.part3.rar
    
    test.part4.rar" [10] => test.part4.rar" [11] => test.part4.rar
    Mentre
    Codice PHP:
    echo $links[0]["$row"]."
    "

    mi restituisce:

    Per link interi intendo https://rapidshare.com/files/3751374383/test.part1.rar, ovvero link funzionanti.

    Il mio problema è tenere soltanto i links senza le virgolette, quindi l'ultimo della serie e associarli a variabile.

    Grazie

  6. #6
    Eccolo funzionante

    Codice PHP:
    foreach ($links as $linksall) {
      if (
    is_array($linksall)) {
          foreach (
    $linksall as $sottolink) {
             echo 
    $sottolink,'
    '
    ;
          }
      }
    }

    unset(
    $sottolink);
    unset(
    $linksall); 
    Mo' mi leggo per benino quello che hai postato...

  7. #7
    Ciao,

    allora guardando il tuo array mi sembra di capire che il link completo è solo nel primo indice del primo sottoarray, cioè nell'array[0].

    Se così, tu potresti ottenere ciò con:
    Codice PHP:
    if (is_array($links[0])) {
          foreach (
    $links[0] as $sottolink) {
             echo 
    $sottolink,'
    '
    ;
          }
      }
    unset(
    $sottolink); 
    Guarda se ti funziona!

  8. #8
    Originariamente inviato da MrsCassandra
    Eccolo funzionante

    Codice PHP:
    foreach ($links as $linksall) {
      if (
    is_array($linksall)) {
          foreach (
    $linksall as $sottolink) {
             echo 
    $sottolink,'
    '
    ;
          }
      }
    }

    unset(
    $sottolink);
    unset(
    $linksall); 
    Mo' mi leggo per benino quello che hai postato...
    Ok, perchè lìho provato ma non va bene..

  9. #9
    Originariamente inviato da MrsCassandra
    Ciao,

    allora guardando il tuo array mi sembra di capire che il link completo è solo nel primo indice del primo sottoarray, cioè nell'array[0].

    Se così, tu potresti ottenere ciò con:
    Codice PHP:
    if (is_array($links[0])) {
          foreach (
    $links[0] as $sottolink) {
             echo 
    $sottolink,'
    '
    ;
          }
      }
    unset(
    $sottolink); 
    Guarda se ti funziona!
    Ok, ci siamo quasi.. devo solo eliminare quelli doppi... Infatti:

    come vedi ci sono https://rapidshare.com/files/3751374383/test.part1.rar" in tutti i casi con le ", dovrei cancellare quelli sbagliati in modo da tenere solo quelli giusti

  10. #10
    Ciao!

    Se devi solo visualizzare quelli senza le virgolette puoi usare stristr() (ti raccomando di dare un'occhiata qui http://php.html.it/guide/lezione/265...e-le-stringhe/ e magari una ripassatina qui http://php.html.it/guide/lezione/265...ire-gli-array/).

    Questo dovrebbe andare...

    Codice PHP:
    if (is_array($links[0])) { 
          foreach (
    $links[0] as $sottolink) { 
             if (!
    stristr($sottolink,'"')) {
                echo 
    $sottolink,'
    '

             }
          } 
      } 
    unset(
    $sottolink); 
    Secondo me dovresti ripulire lo script che crea l'array (o la sorgente dei dati) e comunque evitare di creare array inutili con duplicati (a che ti servono?).


Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.