3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = <<<FOO #Doc 1 ## #Doc1.1 #Doc 1.2 mine_sht : carftj ### 漢字漢字貔貅 (Random chinese symbols) tv: tee # # HI tvw: 9 #Inline doc #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: " . $m . "\nDOC: " . $doc . "\nIDOC: " . $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: #Doc 1 ## #Doc1.1 #Doc 1.2 IDOC: ### 漢字漢字貔貅 (Random chinese symbols) -------------------------------------------------- KEY: tv DOC: IDOC: # # HI -------------------------------------------------- KEY: tvw DOC: IDOC: #Inline doc -------------------------------------------------- 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/2SU5b:20 Stack trace: #0 {main} thrown in /in/2SU5b on line 20
Process exited with code 255.

preferences:
71.71 ms | 407 KiB | 5 Q