3v4l.org

run code in 500+ PHP versions simultaneously
<?php $string = "James said hello\n\n\n\n Test\n Test two\n\n"; echo json_encode( preg_replace("/\n{2,}/", "\n", $string) ); echo "\n---\n"; $string = "James\r\n said\n\r\n hello\r\n\r\n\r\n Test\n Test two\n\n"; echo json_encode( preg_replace("/\R{2,}/", PHP_EOL, $string) );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ZT7gL
function name:  (null)
number of ops:  16
compiled vars:  !0 = $string
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, 'James+said+hello%0A%0A%0A%0A+Test%0A+Test+two%0A%0A'
    4     1        INIT_FCALL                                                   'json_encode'
    5     2        FRAMELESS_ICALL_3                preg_replace        ~2      '%2F%0A%7B2%2C%7D%2F', '%0A'
          3        OP_DATA                                                      !0
          4        SEND_VAL                                                     ~2
    4     5        DO_ICALL                                             $3      
    5     6        ECHO                                                         $3
    8     7        ECHO                                                         '%0A---%0A'
   10     8        ASSIGN                                                       !0, 'James%0D%0A+said%0A%0D%0A+hello%0D%0A%0D%0A%0D%0A+Test%0A+Test+two%0A%0A'
   11     9        INIT_FCALL                                                   'json_encode'
   12    10        FRAMELESS_ICALL_3                preg_replace        ~5      '%2F%5CR%7B2%2C%7D%2F', '%0A'
         11        OP_DATA                                                      !0
         12        SEND_VAL                                                     ~5
   11    13        DO_ICALL                                             $6      
   12    14        ECHO                                                         $6
   13    15      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
150.2 ms | 1899 KiB | 14 Q