3v4l.org

run code in 300+ PHP versions simultaneously
<?php // suppose some data is missing... $data = []; $data["height"]=""; $data['text']="more testing"; // get XML into a variable ... $xml = <<<XML <template> <height>$data[height]</height> <width>$data[height]</width> <text>$data[text]</text> </template> XML; $dom = new DOMDocument; $dom->preserveWhiteSpace = false; $dom->loadXML( $xml ); $template = $dom->getElementsByTagName('template')->item(0); $nodeList = $template->childNodes; echo (function() use($dom,$template,$nodeList){ // iterate backwards to remove node missing value for( $max=$nodeList->length-1, $i=0; $max >= $i; $max-- ) { $currNode = $nodeList->item($max); $status = $currNode->hasChildNodes()? true:false; if ($status === false) { $currNode->parentNode->removeChild( $currNode ); }// end if }// end for return $dom->saveXML( $template ); })(); // immediate executable
Output for git.master, git.master_jit, rfc.property-hooks
<template><text>more testing</text></template>

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:
132.54 ms | 405 KiB | 5 Q