Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This should do the trick, if I'm not mistaken:</p> <pre><code>preg_match_all('/height(\:|\=)"*\s*([0-9]+[^;"]+);*/i','&lt;tr style="height: 123px; border: none;&gt;&lt;tr height="125px"',$matches); var_dump($matches[2]);//array('123px','125px'); </code></pre> <p>But since you're going to let this regex loose on HTML (if I'm not mistaken), I'd look <a href="http://php.net/manual/en/class.domdocument.php" rel="nofollow">at ways to <em>parse</em> the DOM</a> and use the <a href="http://php.net/manual/en/class.domelement.php" rel="nofollow">DOMElement's</a> methods to get what I want. It's a far more robust take on the problem.</p> <p>As requested by OP:</p> <pre><code>function getDeepChildren($node,&amp;$nodeArray) {//recursive function to flatten dom $current = $node-&gt;getElementsByTagName('*');//get all children foreach($current as $node) {//loop through children $nodeArray[] = $node;//add child if ($node-&gt;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-&gt;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-&gt;hasAttribute('height')) { $height[] = array($node-&gt;getAttribute('height'),$node); continue;//already got what we need, no need for slow preg_match //in case of &lt;div height="123px" style="border:1px solid #F00;"&gt; for example... } if ($node-&gt;hasAttribute('style') &amp;&amp; preg_match('/height\s*\:\s*([0-9]+\s*[a-z]+)\s*;/i',$node-&gt;getAttribute('style'),$match)) { $height[] = array($match[1],$node); } } var_dump($height);//should contain everything you're looking for </code></pre> <p>For a more OO approach, I suggest looking at a couple of <a href="http://www.php.net/manual/en/class.domnodelist.php" rel="nofollow">recursive domnode iterator classes</a>.<br/>Passing arrays by reference is discouraged, but it's the easiest way to get what you need here. An alternative version would be:</p> <pre><code>function getDeepChildren($node) { $nodes = array(); $current = $node-&gt;getElementsByTagName('*'); foreach($current as $node) { $nodes[] = $node; if ($node-&gt;hasChildNodes()) { $nodes = array_merge($nodes,getDeepChildren($node)); } } return $nodes; } //instead of getDeepChildren($dom,$nodes), usage is: $nodes = getDeepChildren($dom); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload