3v4l.org

run code in 300+ PHP versions simultaneously
<?php $doc = new DOMDocument(); $doc->loadHTML('<html><body><a href="teste.php">Teste</a><a href="../teste2.php">Teste2</a></body></html>'); $links = $doc->getElementsByTagName('a'); print_r($links); foreach($links as $link) { echo $link->getAttribute('href') . "\n"; } echo $doc->saveHTML() . "\n\n"; $body = $doc->getElementsByTagName('body')[0]; $select = $doc->createElement('select'); $body->appendChild($select); echo $doc->saveHTML() . "\n\n"; function addElement($doc, $newElement, $parentElement, $attributesArray = null) { $pe = $doc->getElementsByTagName($parentElement)[0]; $ne = $doc->createElement($newElement); $pe->appendChild($ne); if (isset($attributesArray)) { while ( ($current = current($attributesArray)) ) { print_r($current); $attrib = key($current); $domAttribute = $doc->createAttribute($attrib); // Value for the created attribute $domAttribute->value = $current[$attrib]; // Don't forget to append it to the element $ne->appendChild($domAttribute); echo $attrib . '=' . $current[$attrib] . "\n"; next($array); } } echo $doc->saveHTML(); } $attribs = [ ['style' => '"border:1px solid black;"'] ]; addElement($doc, 'ul', 'select', $attribs);
Output for git.master, git.master_jit, rfc.property-hooks
DOMNodeList Object ( [length] => 2 ) teste.php ../teste2.php <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html><body><a href="teste.php">Teste</a><a href="../teste2.php">Teste2</a></body></html> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html><body><a href="teste.php">Teste</a><a href="../teste2.php">Teste2</a><select></select></body></html> Array ( [style] => "border:1px solid black;" ) style="border:1px solid black;" Fatal error: Uncaught TypeError: next(): Argument #1 ($array) must be of type array, null given in /in/2LSkY:39 Stack trace: #0 /in/2LSkY(39): next(NULL) #1 /in/2LSkY(49): addElement(Object(DOMDocument), 'ul', 'select', Array) #2 {main} thrown in /in/2LSkY on line 39
Process exited with code 255.

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:
67.51 ms | 402 KiB | 8 Q