3v4l.org

run code in 500+ PHP versions simultaneously
<?php $html = <<<HTML <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>header</title> </head> <body> <input id='printed_name' type='text' class='forma_input' required='' style='position: relative;top: -8px;'> </body> </html> HTML; $doc = new DOMDocument(); $doc->loadHtml($html); $el = $doc->getElementById('printed_name'); $el->setAttribute( "value", "1234" ); var_dump($doc->saveHTML());
Output for 8.0.30, 8.1.22 - 8.1.34, 8.2.9 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
string(239) "<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>header</title> </head> <body> <input id="printed_name" type="text" class="forma_input" required="" style="position: relative;top: -8px;" value="1234"> </body> </html> "
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.29, 8.1.0 - 8.1.21, 8.2.0 - 8.2.8
string(222) "<!DOCTYPE html> <html><head><meta charset="utf-8"><title>header</title></head><body> <input id="printed_name" type="text" class="forma_input" required="" style="position: relative;top: -8px;" value="1234"></body></html> "

preferences:
112.06 ms | 1403 KiB | 4 Q