geting values from html table

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marco

    geting values from html table

    Hello there ;)

    I'm trying to build a scrip that would open a page that has a table and then
    get all the values as variables so I can put them in a MySQL DB.
    The problem is that I don't really know where to start...

    This was my idea split the page in two cause there's 2 tables and I just
    want the second one, then clean up what I don't want and finally assign the
    variables...

    something along these lines... sadly this doesn't work :(

    <?php
    ini_set('error_ reporting', E_ALL);

    ini_set('user_a gent','MSIE 4\.0b2;');

    $handle = fopen("http://www.scuniverse. net/Hist/HOF.htm", "r");
    $page = fread($handle, 20000);
    $row = explode("TR",$p age);

    $i=0;

    while ($i < 31)
    {
    list ($Rank, $Name, $Castle, $Land, $KS, $Race) = explode("TD",$r ow[$i]);
    $i++;
    }





  • Paulius

    #2
    Re: geting values from html table

    "Marco" <mpgtlatbluewin .ch> wrote in message news:<420152be$ 1_2@news.bluewi n.ch>...[color=blue]
    > ini_set('user_a gent','MSIE 4\.0b2;');
    >
    > $handle = fopen("http://www.scuniverse. net/Hist/HOF.htm", "r");
    > $page = fread($handle, 20000);
    > $row = explode("TR",$p age);
    >
    > $i=0;
    >
    > while ($i < 31)
    > {
    > list ($Rank, $Name, $Castle, $Land, $KS, $Race) = explode("TD",$r ow[$i]);
    > $i++;
    > }[/color]

    theoreticly it somethjink like that

    $h=implode("",f ile("somefile/fromsomewhere/test.htm"));
    $h=preg_replace ('/\<[\/]TABLE\>/','--TABLE--',$h);
    list($trash1,$t able,$trash2)=e xplode("--TABLE--",$h);
    $table=preg_rep lace("/\<TR.+\>/","",$table );
    $table=preg_rep lace("/\<TD.+\>/","",$table );
    $row_array=expl ode("</TR>",$table);
    $sz=sizeof($row _array);
    for($i=0; $i < $sz; $i++) {
    list ($Rank, $Name, $Castle, $Land, $KS, $Race)=explode( "</TD>",$row_arra y[$i]);
    }

    i didnt try it :)
    it is simple, lame but it shoud explain the algorythm:)

    Comment

    • Marco

      #3
      Re: geting values from html table


      "Paulius" <madguru@gmail. com> wrote in message
      news:ff4435b2.0 502030141.37afa 7eb@posting.goo gle.com...[color=blue]
      > "Marco" <mpgtlatbluewin .ch> wrote in message
      > news:<420152be$ 1_2@news.bluewi n.ch>...[color=green]
      >> ini_set('user_a gent','MSIE 4\.0b2;');
      >>
      >> $handle = fopen("http://www.scuniverse. net/Hist/HOF.htm", "r");
      >> $page = fread($handle, 20000);
      >> $row = explode("TR",$p age);
      >>
      >> $i=0;
      >>
      >> while ($i < 31)
      >> {
      >> list ($Rank, $Name, $Castle, $Land, $KS, $Race) = explode("TD",$r ow[$i]);
      >> $i++;
      >> }[/color]
      >
      > theoreticly it somethjink like that
      >
      > $h=implode("",f ile("somefile/fromsomewhere/test.htm"));
      > $h=preg_replace ('/\<[\/]TABLE\>/','--TABLE--',$h);
      > list($trash1,$t able,$trash2)=e xplode("--TABLE--",$h);
      > $table=preg_rep lace("/\<TR.+\>/","",$table );
      > $table=preg_rep lace("/\<TD.+\>/","",$table );
      > $row_array=expl ode("</TR>",$table);
      > $sz=sizeof($row _array);
      > for($i=0; $i < $sz; $i++) {
      > list ($Rank, $Name, $Castle, $Land, $KS,
      > $Race)=explode( "</TD>",$row_arra y[$i]);
      > }
      >
      > i didnt try it :)
      > it is simple, lame but it shoud explain the algorythm:)[/color]

      Thanks, didnt try it yet but your idea pleases me already :D


      Comment

      • DH

        #4
        Re: geting values from html table

        Marco wrote:[color=blue]
        > Hello there ;)
        >
        > I'm trying to build a scrip that would open a page that has a table and then
        > get all the values as variables so I can put them in a MySQL DB.
        > The problem is that I don't really know where to start...
        >
        > This was my idea split the page in two cause there's 2 tables and I just
        > want the second one, then clean up what I don't want and finally assign the
        > variables...
        >
        > something along these lines... sadly this doesn't work :(
        >
        > <?php
        > ini_set('error_ reporting', E_ALL);
        >
        > ini_set('user_a gent','MSIE 4\.0b2;');
        >
        > $handle = fopen("http://www.scuniverse. net/Hist/HOF.htm", "r");
        > $page = fread($handle, 20000);
        > $row = explode("TR",$p age);
        >
        > $i=0;
        >
        > while ($i < 31)
        > {
        > list ($Rank, $Name, $Castle, $Land, $KS, $Race) = explode("TD",$r ow[$i]);
        > $i++;
        > }[/color]

        <?php header("Content-Type: application/vnd.ms-excel");?>
        <table border=1>
        <tr><th>col1</th><th>col2</th></tr>
        <tr><td>Cell 1</td><td>Cell 2</td></tr>
        </table>

        Comment

        Working...