...

View Full Version : Better way other than pregmatch? HTML Table Extraction



lawrenceboland
08-09-2007, 09:38 AM
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

usik
08-09-2007, 11:26 AM
well you will want to use regex to extract all the information why not use the split() function?



<?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

lawrenceboland
08-09-2007, 07:32 PM
Hmm thats an interesting way of doing things. I'll give it a try and post my results...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum