Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Better way other than pregmatch? HTML Table Extraction

    I'm trying to extract some (if not all) information out of an html table on this site: http://finance.yahoo.com/q/ae?s=TG

    I may be a php newbie, but I'm getting frustrated trying to preg_match and preg_replace my way between each set of tags. Is there any better way that I'm missing?

    -Bo

  • #2
    New Coder
    Join Date
    Aug 2007
    Location
    Wagga, Australia
    Posts
    59
    Thanks
    0
    Thanked 1 Time in 1 Post
    well you will want to use regex to extract all the information why not use the split() function?

    PHP Code:
    <?php
    //of course this is just an example so i am just pretending I imported this table from yahoo :P
    $table "<table><tr><td>vital information i wish to extract</td></tr></table>";

    //split up the table into an array by the tags to be left with the information between the tags
    $information split("<.[a-z]*>"$table, -1);

    foreach(
    $information as $inform) {
      
    //there will be a lot of blank values within the array, we only want to echo the segments that aren't empty
      
    if(!empty($inform)) {
      echo 
    "$inform<br />";
      }
    }
    ?>
    the following output would be
    vital information i wish to extract

  • #3
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hmm thats an interesting way of doing things. I'll give it a try and post my results...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •