3v4l.org

run code in 300+ PHP versions simultaneously
<?php $htmlData = '<h1><span> test&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span> <span> test&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span> <span> test&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span> <span> test&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span> </h1> '; echo $htmlData = preg_replace_callback('/<li(.*?)>(.*?)<\/li>(.*?)/s', 'replaceRule19Matches', $htmlData); function replaceRule19Matches($matches) { $outString = ''; $matchList = []; preg_match_all('/<span[^>]*>(.*?)<\/span>/s', $matches[0], $matchList); foreach ($matchList[0] as $match) { $htmlToMatch = htmlentities($match); if ((substr_count($htmlToMatch, "&amp;nbsp;") == 5) && (str_word_count($htmlToMatch) == 5)) { $outString = str_replace($match, '<b style="width:14px; display: inline-block;">&nbsp;</b>', $matches[0]); } else if (substr_count($htmlToMatch, "&amp;nbsp;") == 20) { $outString = str_replace($match, '<b style="width:35px; display: inline-block;">&nbsp;</b>', $matches[0]); } } return $outString == '' ? $matches[0] : $outString; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/beRY9
function name:  (null)
number of ops:  9
compiled vars:  !0 = $htmlData
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3Ch1%3E%3Cspan%3E+test%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B+%3C%2Fspan%3E%0A%3Cspan%3E+test%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B+%3C%2Fspan%3E%0A%3Cspan%3E+test%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B+%3C%2Fspan%3E%0A%3Cspan%3E+test%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B+%3C%2Fspan%3E%0A%3C%2Fh1%3E%0A'
    9     1        INIT_FCALL                                               'preg_replace_callback'
          2        SEND_VAL                                                 '%2F%3Cli%28.%2A%3F%29%3E%28.%2A%3F%29%3C%5C%2Fli%3E%28.%2A%3F%29%2Fs'
          3        SEND_VAL                                                 'replaceRule19Matches'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $2      
          6        ASSIGN                                           ~3      !0, $2
          7        ECHO                                                     ~3
   29     8      > RETURN                                                   1

Function replacerule19matches:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 50
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 50
Branch analysis from position: 12
2 jumps found. (Code = 46) Position 1 = 22, Position 2 = 27
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 36
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 42, Position 2 = 49
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 49
Branch analysis from position: 27
Branch analysis from position: 50
2 jumps found. (Code = 43) Position 1 = 53, Position 2 = 56
Branch analysis from position: 53
1 jumps found. (Code = 42) Position 1 = 57
Branch analysis from position: 57
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 56
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 50
filename:       /in/beRY9
function name:  replaceRule19Matches
number of ops:  59
compiled vars:  !0 = $matches, !1 = $outString, !2 = $matchList, !3 = $match, !4 = $htmlToMatch
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
   13     1        ASSIGN                                                   !1, ''
   14     2        ASSIGN                                                   !2, <array>
   15     3        INIT_FCALL                                               'preg_match_all'
          4        SEND_VAL                                                 '%2F%3Cspan%5B%5E%3E%5D%2A%3E%28.%2A%3F%29%3C%5C%2Fspan%3E%2Fs'
          5        FETCH_DIM_R                                      ~7      !0, 0
          6        SEND_VAL                                                 ~7
          7        SEND_REF                                                 !2
          8        DO_ICALL                                                 
   16     9        FETCH_DIM_R                                      ~9      !2, 0
         10      > FE_RESET_R                                       $10     ~9, ->50
         11    > > FE_FETCH_R                                               $10, !3, ->50
   18    12    >   INIT_FCALL                                               'htmlentities'
         13        SEND_VAR                                                 !3
         14        DO_ICALL                                         $11     
         15        ASSIGN                                                   !4, $11
   20    16        INIT_FCALL                                               'substr_count'
         17        SEND_VAR                                                 !4
         18        SEND_VAL                                                 '%26amp%3Bnbsp%3B'
         19        DO_ICALL                                         $13     
         20        IS_EQUAL                                         ~14     $13, 5
         21      > JMPZ_EX                                          ~14     ~14, ->27
         22    >   INIT_FCALL                                               'str_word_count'
         23        SEND_VAR                                                 !4
         24        DO_ICALL                                         $15     
         25        IS_EQUAL                                         ~16     $15, 5
         26        BOOL                                             ~14     ~16
         27    > > JMPZ                                                     ~14, ->36
   21    28    >   INIT_FCALL                                               'str_replace'
         29        SEND_VAR                                                 !3
         30        SEND_VAL                                                 '%3Cb+style%3D%22width%3A14px%3B++display%3A+inline-block%3B%22%3E%26nbsp%3B%3C%2Fb%3E'
         31        FETCH_DIM_R                                      ~17     !0, 0
         32        SEND_VAL                                                 ~17
         33        DO_ICALL                                         $18     
         34        ASSIGN                                                   !1, $18
         35      > JMP                                                      ->49
   22    36    >   INIT_FCALL                                               'substr_count'
         37        SEND_VAR                                                 !4
         38        SEND_VAL                                                 '%26amp%3Bnbsp%3B'
         39        DO_ICALL                                         $20     
         40        IS_EQUAL                                                 $20, 20
         41      > JMPZ                                                     ~21, ->49
   23    42    >   INIT_FCALL                                               'str_replace'
         43        SEND_VAR                                                 !3
         44        SEND_VAL                                                 '%3Cb+style%3D%22width%3A35px%3B++display%3A+inline-block%3B%22%3E%26nbsp%3B%3C%2Fb%3E'
         45        FETCH_DIM_R                                      ~22     !0, 0
         46        SEND_VAL                                                 ~22
         47        DO_ICALL                                         $23     
         48        ASSIGN                                                   !1, $23
   16    49    > > JMP                                                      ->11
         50    >   FE_FREE                                                  $10
   28    51        IS_EQUAL                                                 !1, ''
         52      > JMPZ                                                     ~25, ->56
         53    >   FETCH_DIM_R                                      ~26     !0, 0
         54        QM_ASSIGN                                        ~27     ~26
         55      > JMP                                                      ->57
         56    >   QM_ASSIGN                                        ~27     !1
         57    > > RETURN                                                   ~27
   29    58*     > RETURN                                                   null

End of function replacerule19matches

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.81 ms | 1404 KiB | 25 Q