--------------EDIT------------------------
So i am going with the DOM approach. Here is what I have so far:
One way to make this easier is to use a dom parser http://simplehtmldom.sourceforge.net/ .
You are still going to have to extract the information into an array but this will make it easier to iterate through the elements one by one.
I've updated your edit to fix it.
function tdrows($elements)
{
$str = "";
foreach ($elements as $element) {
$str .= $element->nodeValue . ", ";
}
return $str;
}
function getdata()
{
$contents = "<table><tr><td>Row 1 Column 1</td><td>Row 1 Column 2</td></tr><tr><td>Row 2 Column 1</td><td>Row 2 Column 2</td></tr></table>";
$DOM = new DOMDocument;
$DOM->loadHTML($contents);
$items = $DOM->getElementsByTagName('tr');
foreach ($items as $node) {
echo tdrows($node->childNodes) . "<br />";
}
}
getdata();
You should consider using XML.
It is much easier than HTML table and much more sufficient.
Example: http://www.php.net/manual/en/simplexml.examples-basic.php