What do i do wrong ?

Discussion in 'PHP' started by coladeu, May 12, 2012.

  1. #1
    I need to extract content from a page and i write this code but i dont get all the results.. The results should be 100 and i get only the first result. Can someone help me with this to make it get all the results from each td?
    $site = file_get_contents("http://site.com/page.html");
    $i = 0;
    while($i <= 100)
    {
    $track = explode("<form class='Right' id='frpage1' name='frpage1' method='get' action=''>", $site);
    $track = explode("<div class='Selection' align='center'>", $track[$i]);
    $track = $track[0];
    
    $url= explode("<td width=40%>", $track);
    $url= explode("</td>", $url[1]);
    $url= $url[0];
    
    $name = explode("<td width=35%>", $track);
    $name = explode("</td>", $name[1]);
    $name = $name[0];
    
        ++$i;
        print $url;
    
    }
    Code (markup):

     
    coladeu, May 12, 2012 IP
  2. Oli3L

    Oli3L Active Member

    Messages:
    207
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    70
    #2
    you should try using preg_match_all
     
    Oli3L, May 12, 2012 IP
  3. coladeu

    coladeu Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi Oli3l I tryed with preg match_all and it works good i get all the results on "print_r" but the problem is that i need to fetch from a site to my site and when i do that with preg_match_all, on my site appears only "array" in the name field and urls field and i get some errors from base64 url encoding. I'm not good with preg_match at all. and i don\t know how can i make it to show me the simple results without arrays and numbers just results and to be able to see the results with "print $results;" instead of "print_r ($results); if is possible. i don't know.
    If i had to do it with preg_match i need to do it similar to this one. Can you help me?
     
    coladeu, May 12, 2012 IP
  4. Oli3L

    Oli3L Active Member

    Messages:
    207
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    70
    #4
    well.. you could use implode() to glue together the array cells..
    you can also use foreach() to run over all of the array
     
    Oli3L, May 12, 2012 IP
  5. coladeu

    coladeu Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Ok I have made it like this.
    I get the results but i need the print to be out of {} to be able to make only one print for $nume, $ur; and to implement in my site
     
    coladeu, May 12, 2012 IP