3v4l.org

run code in 300+ PHP versions simultaneously
<?php function handleCharacterData($parser, $data) { echo __FUNCTION__ . " - " . $data . "\n"; } function handleElementStart($parser, $name, $attributes) { echo __FUNCTION__ . " - " . $name . "\n"; } function handleElementEnd($parser, $name) { echo __FUNCTION__ . " - " . $name . "\n"; } function parseAndOutput($s) { $p = xml_parser_create(); xml_parser_set_option($p, XML_OPTION_SKIP_WHITE, 1); xml_set_character_data_handler($p, 'handleCharacterData'); xml_set_element_handler($p, 'handleElementStart', 'handleElementEnd'); xml_parse_into_struct($p, $s, $values); echo $values[0]['value'] . "\n\n"; } $s = "<a>b\nc</a>"; parseAndOutput($s); $s = "<a>&lt;b&gt;\n&lt;c&gt;</a>"; parseAndOutput($s);
Output for 7.4.25 - 7.4.33, 8.0.12 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
handleElementStart - A handleCharacterData - b c handleElementEnd - A b c handleElementStart - A handleCharacterData - < handleCharacterData - b handleCharacterData - > handleCharacterData - handleCharacterData - < handleCharacterData - c handleCharacterData - > handleElementEnd - A <b> <c>
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.24, 8.0.0 - 8.0.11
handleElementStart - A handleCharacterData - b c handleElementEnd - A b c handleElementStart - A handleCharacterData - < handleCharacterData - b handleCharacterData - > handleCharacterData - handleCharacterData - < handleCharacterData - c handleCharacterData - > handleElementEnd - A <b><c>

preferences:
238.47 ms | 404 KiB | 339 Q