3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = <<<'EOD' #1 (1) This is a test. a) This is a subtest one. b) And another one. (2) A really cool test. (3) Here is the problem, text for each numbered line is supposed to be on a single line like in (1) and (2), but the text often spans multiple lines of text. (4) How can I match the multi-line entries and unwrap them to single lines? #2 (1) This is a test. a) This is a subtest one. b) And another one. (2) A really cool test. (3) Here is the problem, text for each numbered line is supposed to be on a single line like in (1) and (2), but the text often spans multiple lines of text. (4) How can I match the multi-line entries and unwrap them to single lines? #3 (1) This is a test. a) This is a subtest one. b) And another one. (2) A really cool test. (3) Here is the problem, text for each numbered line is supposed to be on a single line like in (1) and (2), but the text often spans multiple lines of text. (4) How can I match the multi-line entries and unwrap them to single lines? a) dfk EOD; print_r(preg_split('~(\R+|^#\d+$)+(?=\(\d+\)|[a-z]\)|\z)~m', $str, -1, PREG_SPLIT_NO_EMPTY));
Output for 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.30, 8.3.0 - 8.3.4, 8.3.6 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
Array ( [0] => (1) This is a test. [1] => a) This is a subtest one. [2] => b) And another one. [3] => (2) A really cool test. [4] => (3) Here is the problem, text for each numbered line is supposed to be on a single line like in (1) and (2), but the text often spans multiple lines of text. [5] => (4) How can I match the multi-line entries and unwrap them to single lines? [6] => (1) This is a test. [7] => a) This is a subtest one. [8] => b) And another one. [9] => (2) A really cool test. [10] => (3) Here is the problem, text for each numbered line is supposed to be on a single line like in (1) and (2), but the text often spans multiple lines of text. [11] => (4) How can I match the multi-line entries and unwrap them to single lines? [12] => (1) This is a test. [13] => a) This is a subtest one. [14] => b) And another one. [15] => (2) A really cool test. [16] => (3) Here is the problem, text for each numbered line is supposed to be on a single line like in (1) and (2), but the text often spans multiple lines of text. [17] => (4) How can I match the multi-line entries and unwrap them to single lines? [18] => a) dfk )
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Array ( [0] => (1) This is a test. [1] => a) This is a subtest one. [2] => b) And another one. [3] => (2) A really cool test. [4] => (3) Here is the problem, text for each numbered line is supposed to be on a single line like in (1) and (2), but the text often spans multiple lines of text. [5] => (4) How can I match the multi-line entries and unwrap them to single lines? [6] => (1) This is a test. [7] => a) This is a subtest one. [8] => b) And another one. [9] => (2) A really cool test. [10] => (3) Here is the problem, text for each numbered line is supposed to be on a single line like in (1) and (2), but the text often spans multiple lines of text. [11] => (4) How can I match the multi-line entries and unwrap them to single lines? [12] => (1) This is a test. [13] => a) This is a subtest one. [14] => b) And another one. [15] => (2) A really cool test. [16] => (3) Here is the problem, text for each numbered line is supposed to be on a single line like in (1) and (2), but the text often spans multiple lines of text. [17] => (4) How can I match the multi-line entries and unwrap them to single lines? [18] => a) dfk )

preferences:
113.32 ms | 1647 KiB | 4 Q