3v4l.org

run code in 300+ PHP versions simultaneously
<?php $tests = [ " \ntest1 \n \t \ntest1\n\n " => "test1\ntest1", " \r\ntest2 \r\n \t \r\ntest2\r\n\r\n " => "test2\r\ntest2", " \u{0085}test3 \u{0085} \t \u{0085}test3\u{0085}\u{0085} " => "test3\u{0085}test3", " \u{2029}test4 \u{2029} \t \u{2029}test4\u{2029}\u{2029} " => "test4\u{2029}test4", " \ftest5 \f \t \ftest5\f\f " => "test5\ftest5", " \rtest6 \r \t \r\rtest6\r\r " => "test6\rtest6", ]; $i = 0; $pattern = '~(*ANY)\A\s*\R|\s*(?!\r\n)\s$~mu'; foreach($tests as $input => $output) { echo 'Test', ++$i, ': ', (preg_replace($pattern, '', $input) === $output ? 'SUCCESS':'FAIL'), PHP_EOL; }
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
Test1: SUCCESS Test2: SUCCESS Test3: SUCCESS Test4: SUCCESS Test5: SUCCESS Test6: SUCCESS

preferences:
65.11 ms | 1120 KiB | 4 Q