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

08-09-2007, 08: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?


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

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

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