3v4l.org

run code in 500+ PHP versions simultaneously
<?php $html = ' <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>We <em>love</em> HTML!</title> </head> <body> </body> </html> '; function run_tests( $document ) { $title = $document->getElementsByTagName( 'title' )->item( 0 ); if ( $title->childNodes->length !== 1 ) { echo "FAIL: Title tag does not have the the expected single text child. Has {$title->childNodes->length} children.\n"; } else { echo "PASS: Title tag only has a single child.\n"; } if ( $title->getElementsByTagName( 'em' )->length !== 0 ) { echo "FAIL: Title tag unexpectedly has a parsed EM child.\n"; } else { echo "PASS: Title tag has no child EM element.\n"; } if ( false !== strpos( $title->textContent, '<em>' ) ) { echo "PASS: HTML tag <em> was not parsed. Text content: {$title->textContent}\n"; } else { echo "FAIL: HTML tag <em> was parsed. Text content: {$title->textContent}\n"; } } echo "# DOMDocument:\n"; $old_document = new DOMDocument(); $old_document->loadHTML( $html ); run_tests( $old_document ); echo "\n"; echo "# Dom\HTMLDocument:\n"; if ( class_exists( Dom\HTMLDocument::class ) ) { $new_document = Dom\HTMLDocument::createFromString( $html ); run_tests( $new_document ); } else { echo "(Not available)\n"; }
Output for 8.4.1 - 8.4.25, 8.5.0 - 8.5.10
# DOMDocument: FAIL: Title tag does not have the the expected single text child. Has 3 children. FAIL: Title tag unexpectedly has a parsed EM child. FAIL: HTML tag <em> was parsed. Text content: We love HTML! # Dom\HTMLDocument: PASS: Title tag only has a single child. PASS: Title tag has no child EM element. PASS: HTML tag <em> was not parsed. Text content: We <em>love</em> HTML!
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.33, 8.3.0 - 8.3.33
# DOMDocument: FAIL: Title tag does not have the the expected single text child. Has 3 children. FAIL: Title tag unexpectedly has a parsed EM child. FAIL: HTML tag <em> was parsed. Text content: We love HTML! # Dom\HTMLDocument: (Not available)
Output for 5.4.0 - 5.4.45
Parse error: syntax error, unexpected 'class' (T_CLASS), expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in /in/oDUI3 on line 41
Process exited with code 255.
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected T_CLASS, expecting T_STRING or T_VARIABLE or '$' in /in/oDUI3 on line 41
Process exited with code 255.
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/oDUI3 on line 41 Parse error: syntax error, unexpected T_STRING in /in/oDUI3 on line 41
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/oDUI3 on line 41 Parse error: parse error, unexpected T_STRING in /in/oDUI3 on line 41
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /in/oDUI3 on line 16
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_OBJECT_OPERATOR in /in/oDUI3 on line 16
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/oDUI3 on line 16
Process exited with code 255.

preferences:
58.66 ms | 2881 KiB | 4 Q