Extract html table

Hey guys, I have a HTML table with the following

[code]


10 BAR
10A Bana
A
<tr class="dTr">
    <td class="dTd3ColL">O'CLOCK DAIRY</td>
    <td class="dTd3ColL">100 Albert Road</td>
    <td class="dTd3ColR">B</td>
</tr>

[/code]

I’m at a loss how to extract the sets of data. So first TR I want to pull (10 BAR, 10A Bana, A) as ($Var1,$Var2,$Var3) process them, then move onto the next TR and do the same.
How would I go about this.

Thankyou,
Greg

I dont know if this function will help you

Get string inside of any html tag
[php]
function getStringBetweenTags($haystack, $tagname) {
$needle = “/<$tagname ?.>(.)</$tagname>/”;
preg_match($needle, $haystack, $matches);
return $matches[1];
}

[/php]

usage:
[php]
$str = “

10 BAR”;
$txt = getStringBetweenTags($str, “td”);
echo $txt;
[/php]

the result should be “10 BAR”

Thanks for your reply.
preg_match_all() seems to be what I need to use. I have always been terrible at the pattern though.

$_POST[‘dump’] is

[code]


10 BAR
10A Bana
A
<tr class="dTr">
    <td class="dTd3ColL">O'CLOCK DAIRY</td>
    <td class="dTd3ColL">100 Albert Road</td>
    <td class="dTd3ColR">B</td>
</tr>	[/code]

preg_match_all("/<td ?.>(.)</td>/",$_POST[‘dump’],$return, PREG_PATTERN_ORDER);
print_r($return);

This returns

Array ( [0] => Array ( [0] => 10 BAR [1] => 10A Bana [2] => A [3] => O'CLOCK DAIRY [4] => 100 Albert Road [5] => B ) [1] => Array ( [0] => 10 BAR [1] => 10A Bana [2] => A [3] => O'CLOCK DAIRY [4] => 100 Albert Road [5] => B ) )

Why does it create two array sets?

[php] preg_match_all("/<td ?.>(.)</td>/",$_POST[‘dump’],$return, PREG_PATTERN_ORDER);
$len = count($return[0], COUNT_RECURSIVE);
for ($i=0; $i< $len; $i++) {
echo $return[0][$i];
}[/php]

Returns all data stored. So now if I do the data storage in sets of 3, I should be able to store $Var1,$Var2,$Var3 - $Var1,$Var2,$Var3- $Var1,$Var2,$Var3 etc…

Why does it create two array sets?

Because the first set is the matched data based on pattern and the second is the information pulled from data.
I then noticed that one of the bits of data had a link in it.
So this is what I ended up with.

[code]


10 BAR
10A Bana
A
<tr class="dTr">
    <td class="dTd3ColL">O'CLOCK DAIRY</td>
    <td class="dTd3ColL">100 Albert Road</td>
    <td class="dTd3ColR"><a href="/grades-and-classes#grades">B</a></td>
</tr>[/code]

Processed with
[php] preg_match_all("/<td ?.>(.)</td>/",$_POST[‘dump’],$return, PREG_PATTERN_ORDER);
$len = count($return[0], COUNT_RECURSIVE);
for ($i=0; $i< $len; $i++) {
if($n == 3){ $n == 0;}
$n++;
if($n == 3){
preg_match_all("/<td ?.><a ?.>(.*)</a></td>/",$return[0][$i],$health, PREG_PATTERN_ORDER);
$value = $health[1][0];
$Script->storeCompanies($value,$n);
}else{
$value = $return[1][$i];
$Script->storeCompanies($value,$n);
}
}[/php]

In the database
10 BAR | 10A Bana | A
O’CLOCK DAIRY | 100 Albert Road | B

Sponsor our Newsletter | Privacy Policy | Terms of Service