This should do the trick, if I'm not mistaken:
preg_match_all('/height(\:|\=)"*\s*([0-9]+[^;"]+);*/i','<tr style="height: 123px; border: none;><tr height="125px"',$matches);
var_dump($matches[2]);//array('123px','125px');
But since you're going to let this regex loose on HTML (if I'm not mistaken), I'd look at ways to parse the DOM and use the DOMElement's methods to get what I want. It's a far more robust take on the problem.
As requested by OP:
function getDeepChildren($node,&$nodeArray)
{//recursive function to flatten dom
$current = $node->getElementsByTagName('*');//get all children
foreach($current as $node)
{//loop through children
$nodeArray[] = $node;//add child
if ($node->hasChildNodes())
{//if child node has children of its own
getDeepChildren($node,$nodeArray);//get the children and append to nodeArray
}
}
}//no return value, $nodeArray is passed by reference
$dom = new DOMDocument();
$dom->loadHTML($body);
$nodes = array();
getDeepChildren($dom,$nodes);//$nodes is passed by reference
$height = array();
while($node = array_shift($nodes))
{//$height[i][0] === height value, $height[i][1] is reference to node
if ($node->hasAttribute('height'))
{
$height[] = array($node->getAttribute('height'),$node);
continue;//already got what we need, no need for slow preg_match
//in case of <div height="123px" style="border:1px solid #F00;"> for example...
}
if ($node->hasAttribute('style') && preg_match('/height\s*\:\s*([0-9]+\s*[a-z]+)\s*;/i',$node->getAttribute('style'),$match))
{
$height[] = array($match[1],$node);
}
}
var_dump($height);//should contain everything you're looking for
For a more OO approach, I suggest looking at a couple of recursive domnode iterator classes.
Passing arrays by reference is discouraged, but it's the easiest way to get what you need here. An alternative version would be:
function getDeepChildren($node)
{
$nodes = array();
$current = $node->getElementsByTagName('*');
foreach($current as $node)
{
$nodes[] = $node;
if ($node->hasChildNodes())
{
$nodes = array_merge($nodes,getDeepChildren($node));
}
}
return $nodes;
}
//instead of getDeepChildren($dom,$nodes), usage is:
$nodes = getDeepChildren($dom);