3v4l.org

run code in 300+ PHP versions simultaneously
<!DOCTYPE html> <html> <head> INSERT VALUES OF THE GIVEN PHRASE IDS :</head> <!-- <head> <link rel="stylesheet" type="text/css" href="style.css" /></head> --> <body> <form name="form" action="" method="post"> <?php $file = <<<XML <?xml version="1.0"?> <?xml-stylesheet href="catalog.xsl" type="text/xsl"?> <!DOCTYPE catalog SYSTEM "catalog.dtd"> <catalog> <product description="Cardigan Sweater" id="123" value="" product_image="cardigan.jpg"> <catalog_item gender="Men's"> <size description="Medium"> <color_swatch image="red_cardigan.jpg" id="color" value="Red"/> <color_swatch image="burgundy_cardigan.jpg" id="color" value="burgundy"/> </size> <size description="Large"> <color_swatch image="red_cardigan.jpg" id="color" value="Red"/> <color_swatch image="burgundy_cardigan.jpg" id="color" value="burgundy"/> </size> </catalog_item> </product> </catalog> XML; /** * @param SimpleXMLElement $node current node to process * @param int $level Depth in the XML tree * @param string $fieldPrefix */ function makeNodeField(SimpleXMLElement $node, $level, $fieldPrefix = "") { // Indentation with the node level $indent = str_repeat(" ", $level); echo $indent, $node->getName(), PHP_EOL; $fieldName = $fieldPrefix; // If there's an ID on the node, display it and show a text field if (isset($node['id'])) { echo $indent, strval($node['id']), ' '; if (!empty($fieldPrefix)) { $fieldName .= '_'; } $fieldName .= $node->getName() . '_' . strval($node['id']); printf('<input type="text" name="%s" value="%s" /><br/>', $fieldName, strval($node['value'])); echo PHP_EOL; } $count = 0; foreach ($node as $childNode) { // put a prefix in the children field name to get a valid field name for POST $childPrefix = $fieldName; if (!empty($fieldPrefix)) { $childPrefix = $fieldName . '_' . $count++; } makeNodeField($childNode, $level + 1, $childPrefix); } } $xml = simplexml_load_string($file); makeNodeField($xml, 0); ?> </form> </body> </html>

preferences:
24.97 ms | 406 KiB | 5 Q