3v4l.org

run code in 300+ PHP versions simultaneously
<?php $doc_comment = "test\r\nreturns\rare\r\nreplaced as expected"; print "\n\npreg_replace (broken):\n"; var_dump(preg_replace('/\r\n|\r/', '\n', $doc_comment)); print "\n\npreg_replace (fixed):\n"; var_dump(preg_replace('/\r\n|\r/', "\n", $doc_comment)); print "\n\nstr_replace:\n"; var_dump(str_replace(['\r\n', '\r'], ['\n', '\n'], $doc_comment)); print "\n\nstr_replace (double quotes):\n"; var_dump(str_replace(["\r\n", "\r"], "\n", $doc_comment));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hTIOV
function name:  (null)
number of ops:  38
compiled vars:  !0 = $doc_comment
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, 'test%0D%0Areturns%0Dare%0D%0Areplaced+as+expected'
    4     1        ECHO                                                     '%0A%0Apreg_replace+%28broken%29%3A%0A'
    5     2        INIT_FCALL                                               'var_dump'
          3        INIT_FCALL                                               'preg_replace'
          4        SEND_VAL                                                 '%2F%5Cr%5Cn%7C%5Cr%2F'
          5        SEND_VAL                                                 '%5Cn'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $2      
          8        SEND_VAR                                                 $2
          9        DO_ICALL                                                 
    6    10        ECHO                                                     '%0A%0Apreg_replace+%28fixed%29%3A%0A'
    7    11        INIT_FCALL                                               'var_dump'
         12        INIT_FCALL                                               'preg_replace'
         13        SEND_VAL                                                 '%2F%5Cr%5Cn%7C%5Cr%2F'
         14        SEND_VAL                                                 '%0A'
         15        SEND_VAR                                                 !0
         16        DO_ICALL                                         $4      
         17        SEND_VAR                                                 $4
         18        DO_ICALL                                                 
    8    19        ECHO                                                     '%0A%0Astr_replace%3A%0A'
    9    20        INIT_FCALL                                               'var_dump'
         21        INIT_FCALL                                               'str_replace'
         22        SEND_VAL                                                 <array>
         23        SEND_VAL                                                 <array>
         24        SEND_VAR                                                 !0
         25        DO_ICALL                                         $6      
         26        SEND_VAR                                                 $6
         27        DO_ICALL                                                 
   10    28        ECHO                                                     '%0A%0Astr_replace+%28double+quotes%29%3A%0A'
   11    29        INIT_FCALL                                               'var_dump'
         30        INIT_FCALL                                               'str_replace'
         31        SEND_VAL                                                 <array>
         32        SEND_VAL                                                 '%0A'
         33        SEND_VAR                                                 !0
         34        DO_ICALL                                         $8      
         35        SEND_VAR                                                 $8
         36        DO_ICALL                                                 
         37      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.56 ms | 1401 KiB | 19 Q