3v4l.org

run code in 300+ PHP versions simultaneously
<?php // test function: function parse($html) { // I have split the pattern in two lines not to have long lines alerts by the PHP.net form: $pattern = "/<([\w]+)([^>]*?)(([\s]*\/>)|". "(>((([^<]*?|<\!\-\-.*?\-\->)|(?R))*)<\/\\1[\s]*>))/sm"; preg_match_all($pattern, $html, $matches, PREG_OFFSET_CAPTURE); $elements = array(); foreach ($matches[0] as $key => $match) { $elements[] = (object)array( 'node' => $match[0], 'offset' => $match[1], 'tagname' => $matches[1][$key][0], 'attributes' => isset($matches[2][$key][0]) ? $matches[2][$key][0] : '', 'omittag' => ($matches[4][$key][1] > -1), // boolean 'inner_html' => isset($matches[6][$key][0]) ? $matches[6][$key][0] : '' ); } return $elements; } // random html nodes as example: $html = <<<EOD <div id="airport"> <div geo:position="1.234324,3.455546" class="index"> <!-- comment test: <div class="index_top" /> --> <div class="element decorator"> <ul class="lister"> <li onclick="javascript:item.showAttribute('desc');"> <h3 class="outline"> <a href="http://php.net/manual/en/regexp.reference.recursive.php" onclick="openPopup()">Link</a> </h3> <div class="description">Sample description</div> </li> </ul> </div> <div class="clean-line"></div> </div> </div> <div id="omittag_test" rel="rootChild" /> EOD; // application: $elements = parse($html); if (count($elements) > 0) { echo "Elements found: <b>".count($elements)."</b><br />"; foreach ($elements as $element) { echo "<p>Tpl node: <pre>".htmlentities($element->node)."</pre> Tagname: <tt>".$element->tagname."</tt><br /> Attributes: <tt>".$element->attributes."</tt><br /> Omittag: <tt>".($element->omittag ? 'true' : 'false')."</tt><br /> Inner HTML: <pre>".htmlentities($element->inner_html)."</pre></p>"; } } ?>
Output for git.master, git.master_jit, rfc.property-hooks
Elements found: <b>2</b><br /><p>Tpl node: <pre>&lt;div id=&quot;airport&quot;&gt; &lt;div geo:position=&quot;1.234324,3.455546&quot; class=&quot;index&quot;&gt; &lt;!-- comment test: &lt;div class=&quot;index_top&quot; /&gt; --&gt; &lt;div class=&quot;element decorator&quot;&gt; &lt;ul class=&quot;lister&quot;&gt; &lt;li onclick=&quot;javascript:item.showAttribute(&#039;desc&#039;);&quot;&gt; &lt;h3 class=&quot;outline&quot;&gt; &lt;a href=&quot;http://php.net/manual/en/regexp.reference.recursive.php&quot; onclick=&quot;openPopup()&quot;&gt;Link&lt;/a&gt; &lt;/h3&gt; &lt;div class=&quot;description&quot;&gt;Sample description&lt;/div&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;div class=&quot;clean-line&quot;&gt;&lt;/div&gt; &lt;/div&gt; &lt;/div&gt;</pre> Tagname: <tt>div</tt><br /> Attributes: <tt> id="airport"</tt><br /> Omittag: <tt>false</tt><br /> Inner HTML: <pre> &lt;div geo:position=&quot;1.234324,3.455546&quot; class=&quot;index&quot;&gt; &lt;!-- comment test: &lt;div class=&quot;index_top&quot; /&gt; --&gt; &lt;div class=&quot;element decorator&quot;&gt; &lt;ul class=&quot;lister&quot;&gt; &lt;li onclick=&quot;javascript:item.showAttribute(&#039;desc&#039;);&quot;&gt; &lt;h3 class=&quot;outline&quot;&gt; &lt;a href=&quot;http://php.net/manual/en/regexp.reference.recursive.php&quot; onclick=&quot;openPopup()&quot;&gt;Link&lt;/a&gt; &lt;/h3&gt; &lt;div class=&quot;description&quot;&gt;Sample description&lt;/div&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;div class=&quot;clean-line&quot;&gt;&lt;/div&gt; &lt;/div&gt; </pre></p><p>Tpl node: <pre>&lt;div id=&quot;omittag_test&quot; rel=&quot;rootChild&quot; /&gt;</pre> Tagname: <tt>div</tt><br /> Attributes: <tt> id="omittag_test" rel="rootChild"</tt><br /> Omittag: <tt>true</tt><br /> Inner HTML: <pre></pre></p>

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
39 ms | 409 KiB | 8 Q