3v4l.org

run code in 300+ PHP versions simultaneously
<?php $message = "This is a string using the terms? Wait here's one\n abukuma kai\nabukuma-kai\nabukuma\nabukuma\nkai abukuma abukuma kai"; $search = array( 'abukuma kai', 'abukuma' ); $replacements = array( '<a href="http://kancolle.wikia.com/wiki/Abukuma#Upgrade" class="screenshot" rel="ship/Abukuma_Kai.png" style="color:#0073e6; font-weight:bold; border-bottom: 1px #0073e6 dashed;"><p id="yosup">Abukuma Kai</p></a>', '<a href="http://kancolle.wikia.com/wiki/Abukuma#Basic" class="screenshot" rel="ship/Abukuma.png" style="color:#0073e6; font-weight:bold; border-bottom: 1px #0073e6 dashed;">Abukuma</a>' ); function replaceStrings($haystack, $needle, $replacement, $offset = 0) { if (count($needle) != count($replacement)) { throw new \InvalidArgumentException('Needle length must match replacement length'); } $regexpDelimiter = '/'; $wordDelimiter = '[-\s_]'; if (is_array($needle)) { $massagedNeedles = array_map( function($s) use($regexpDelimiter, $wordDelimiter) { $s = preg_quote($s, $regexpDelimiter); $s = preg_replace('/' . $wordDelimiter . '/', $wordDelimiter, $s); return $s; }, $needle ); $regexp = implode('|', $massagedNeedles); } else { $regexp = preg_replace('/' . $wordDelimiter . '/', preg_quote($needle, '/')); } $regexp = sprintf('/%s/i', $regexp); $strpos = preg_match($regexp, $haystack, $matches, 0, $offset); if ($strpos === false) { return $haystack; } var_dump($strpos); exit; return replaceStrings($haystack, $needle, $replacement, $offset); } replaceStrings($message, $search, $replacements);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8hLqN
function name:  (null)
number of ops:  9
compiled vars:  !0 = $message, !1 = $search, !2 = $replacements
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 'This+is+a+string+using+the+terms%3F++Wait+here%27s+one%0A+abukuma+kai%0Aabukuma-kai%0Aabukuma%0Aabukuma%0Akai+abukuma+abukuma+kai'
    5     1        ASSIGN                                                   !1, <array>
   10     2        ASSIGN                                                   !2, <array>
   54     3        INIT_FCALL                                               'replacestrings'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        SEND_VAR                                                 !2
          7        DO_FCALL                                      0          
          8      > RETURN                                                   1

Function replacestrings:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 12
Branch analysis from position: 8
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 30
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
2 jumps found. (Code = 43) Position 1 = 56, Position 2 = 57
Branch analysis from position: 56
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 57
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 56, Position 2 = 57
Branch analysis from position: 56
Branch analysis from position: 57
filename:       /in/8hLqN
function name:  replaceStrings
number of ops:  69
compiled vars:  !0 = $haystack, !1 = $needle, !2 = $replacement, !3 = $offset, !4 = $regexpDelimiter, !5 = $wordDelimiter, !6 = $massagedNeedles, !7 = $regexp, !8 = $strpos, !9 = $matches
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV_INIT                                        !3      0
   16     4        COUNT                                            ~10     !1
          5        COUNT                                            ~11     !2
          6        IS_NOT_EQUAL                                             ~10, ~11
          7      > JMPZ                                                     ~12, ->12
   17     8    >   NEW                                              $13     'InvalidArgumentException'
          9        SEND_VAL_EX                                              'Needle+length+must+match+replacement+length'
         10        DO_FCALL                                      0          
         11      > THROW                                         0          $13
   20    12    >   ASSIGN                                                   !4, '%2F'
   21    13        ASSIGN                                                   !5, '%5B-%5Cs_%5D'
   23    14        TYPE_CHECK                                  128          !1
         15      > JMPZ                                                     ~17, ->30
   24    16    >   INIT_FCALL                                               'array_map'
   25    17        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F8hLqN%3A25%240'
         18        BIND_LEXICAL                                             ~18, !4
         19        BIND_LEXICAL                                             ~18, !5
   31    20        SEND_VAL                                                 ~18
   32    21        SEND_VAR                                                 !1
         22        DO_ICALL                                         $19     
   24    23        ASSIGN                                                   !6, $19
   35    24        INIT_FCALL                                               'implode'
         25        SEND_VAL                                                 '%7C'
         26        SEND_VAR                                                 !6
         27        DO_ICALL                                         $21     
         28        ASSIGN                                                   !7, $21
         29      > JMP                                                      ->41
   37    30    >   INIT_FCALL                                               'preg_replace'
         31        CONCAT                                           ~23     '%2F', !5
         32        CONCAT                                           ~24     ~23, '%2F'
         33        SEND_VAL                                                 ~24
         34        INIT_FCALL                                               'preg_quote'
         35        SEND_VAR                                                 !1
         36        SEND_VAL                                                 '%2F'
         37        DO_ICALL                                         $25     
         38        SEND_VAR                                                 $25
         39        DO_ICALL                                         $26     
         40        ASSIGN                                                   !7, $26
   40    41    >   INIT_FCALL                                               'sprintf'
         42        SEND_VAL                                                 '%2F%25s%2Fi'
         43        SEND_VAR                                                 !7
         44        DO_ICALL                                         $28     
         45        ASSIGN                                                   !7, $28
   42    46        INIT_FCALL                                               'preg_match'
         47        SEND_VAR                                                 !7
         48        SEND_VAR                                                 !0
         49        SEND_REF                                                 !9
         50        SEND_VAL                                                 0
         51        SEND_VAR                                                 !3
         52        DO_ICALL                                         $30     
         53        ASSIGN                                                   !8, $30
   44    54        TYPE_CHECK                                    4          !8
         55      > JMPZ                                                     ~32, ->57
   45    56    > > RETURN                                                   !0
   48    57    >   INIT_FCALL                                               'var_dump'
         58        SEND_VAR                                                 !8
         59        DO_ICALL                                                 
   49    60      > EXIT                                                     
   51    61*       INIT_FCALL_BY_NAME                                       'replaceStrings'
         62*       SEND_VAR_EX                                              !0
         63*       SEND_VAR_EX                                              !1
         64*       SEND_VAR_EX                                              !2
         65*       SEND_VAR_EX                                              !3
         66*       DO_FCALL                                      0  $34     
         67*       RETURN                                                   $34
   52    68*     > RETURN                                                   null

End of function replacestrings

Function %00%7Bclosure%7D%2Fin%2F8hLqN%3A25%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8hLqN
function name:  {closure}
number of ops:  18
compiled vars:  !0 = $s, !1 = $regexpDelimiter, !2 = $wordDelimiter
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        BIND_STATIC                                              !2
   26     3        INIT_FCALL                                               'preg_quote'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                         $3      
          7        ASSIGN                                                   !0, $3
   28     8        INIT_FCALL                                               'preg_replace'
          9        CONCAT                                           ~5      '%2F', !2
         10        CONCAT                                           ~6      ~5, '%2F'
         11        SEND_VAL                                                 ~6
         12        SEND_VAR                                                 !2
         13        SEND_VAR                                                 !0
         14        DO_ICALL                                         $7      
         15        ASSIGN                                                   !0, $7
   30    16      > RETURN                                                   !0
   31    17*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F8hLqN%3A25%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
191.25 ms | 1406 KiB | 28 Q