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( // here all replaces | each in a new line - watch the syntax // all html possible, but no single quotation mark! '<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) { $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('|', $massagedNeedes); } 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($matches); exit; return replaceStrings($haystack, $needle, $replacement, $offset); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ZLMNm
function name:  (null)
number of ops:  4
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>
   50     3      > RETURN                                                   1

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

End of function replacestrings

Function %00%7Bclosure%7D%2Fin%2FZLMNm%3A23%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ZLMNm
function name:  {closure}
number of ops:  18
compiled vars:  !0 = $s, !1 = $regexpDelimiter, !2 = $wordDelimiter
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        BIND_STATIC                                              !2
   24     3        INIT_FCALL                                               'preg_quote'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                         $3      
          7        ASSIGN                                                   !0, $3
   26     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
   28    16      > RETURN                                                   !0
   29    17*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FZLMNm%3A23%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.21 ms | 1409 KiB | 27 Q