3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = <<<FOO #shit ## #shit2 #sshit3 mine_sht : carftj ### 漢字漢字貔貅 tv: tee # # HI tvw: 9 #haha #aa 9abaa: ahah #heuens FOO; preg_match_all('~^\s*(?:(\w+)\s*:.[^\r\n#]*([^\r\n]*#*)?)?(#*(?:[^\r\n]|[\r\n]#)*)~um', $data, $matches); ///print_r($matches); $doc = ""; foreach($matches[1] as $i => $m) { $s = preg_replace('/\s+/', '', $m); //Remove whitespace if (str_starts_with($s, "#") || empty($s)){ //Valid next comment line $doc .= $matches[3][$i] . PHP_EOL; //Adding comments //print("DOC LOG: " . $doc . PHP_EOL); //LOG DOC continue; } print("KEY:\n" . $m . "\nDOC:\n" . $doc . "\nIDOC:\n" . $matches[2][$i] . "\n"); print("--------------------------------------------------\n"); $doc = $matches[3][$i]; //print("OPEN: ". $m . "-CLOSED\n"); }
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.30, 8.2.0 - 8.2.24, 8.3.0 - 8.3.12
KEY: mine_sht DOC: #shit ## #shit2 #sshit3 IDOC: ### 漢字漢字貔貅 -------------------------------------------------- KEY: tv DOC: IDOC: # # HI -------------------------------------------------- KEY: tvw DOC: IDOC: #haha -------------------------------------------------- KEY: 9abaa DOC: #aa IDOC: --------------------------------------------------
Output for 7.4.0 - 7.4.33
Fatal error: Uncaught Error: Call to undefined function str_starts_with() in /in/T3Ov8:20 Stack trace: #0 {main} thrown in /in/T3Ov8 on line 20
Process exited with code 255.

preferences:
70.19 ms | 407 KiB | 5 Q