3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* Paul's Simple Diff Algorithm v 0.1 (C) Paul Butler 2007 <http://www.paulbutler.org/> May be used and distributed under the zlib/libpng license. */ function diff($old, $new){ $matrix = array(); $maxlen = 0; foreach($old as $oindex => $ovalue){ $nkeys = array_keys($new, $ovalue); foreach($nkeys as $nindex){ $matrix[$oindex][$nindex] = isset($matrix[$oindex - 1][$nindex - 1]) ? $matrix[$oindex - 1][$nindex - 1] + 1 : 1; if($matrix[$oindex][$nindex] > $maxlen){ $maxlen = $matrix[$oindex][$nindex]; $omax = $oindex + 1 - $maxlen; $nmax = $nindex + 1 - $maxlen; } } } if($maxlen == 0) return array(array('d'=>$old, 'i'=>$new)); return array_merge( diff(array_slice($old, 0, $omax), array_slice($new, 0, $nmax)), array_slice($new, $nmax, $maxlen), diff(array_slice($old, $omax + $maxlen), array_slice($new, $nmax + $maxlen))); } function htmlDiff($old, $new){ $ret = ''; $diff = diff(preg_split("/[\s]+/", $old), preg_split("/[\s]+/", $new)); foreach($diff as $k){ if(is_array($k)) $ret .= (!empty($k['d'])?"<del>".implode(' ',$k['d'])."</del> ":''). (!empty($k['i'])?"<ins>".implode(' ',$k['i'])."</ins> ":''); else $ret .= $k . ' '; } return $ret; } $old = "We smsfactory are world's leading SMS messaging provider offering remarakable and reliable SMS Text and Voice messaging globally through almost all-networks of mobile phones successfully. You may contact-us anytime for making any query. Our Services are very useful economically as well as eco-friendly"; $new = "We smsfactory are world's leading SMS messaging provider offering remarakable and reliable SMS Text and Voice messaging globally through almost all-networks of mobile phones successfully. You may contact-us anytime for making any query. Our Services are very useful economically as well as eco-friendly, which enables you to send simultaneous bulk sms to your targeted Customers, Regular-Customers, Buyers, Shoppers, Fans, Regular-shoppers, Clients, Clientele, Members, Managers, Supervisors, Fieldworkers, Graduates, Post graduates, Technicians, Public, Citizens, Mobile-Users, Viewers, Future-purchasers, Users, End-users, Students, Job-seekers, Enjoyers, Visitors, Frequent-visitors, Persons, Individuals, Frequenter, Obtainers, Receivers, Assignees, Recipients, Travelers, Tourists, Guys, Persons, Men and Women, Spectators, Technicians, Staff, Workers, Recruiters, Newcomers, Representatives, Dealers, Distributors, Followers, Shareholders, Investors, Bondholders, Shareowners, Financiers, Bankers, Participants, Associates, Assistants, Colleagues, Contributors, Helpers, Partakers, Party, Sharers, Supporters, Admirers, Devotees, Groupies, Enthusiasts and many more."; ?> <!doctype html> <head> <style> .container { width: 50%; margin-right: auto; margin-left: auto; font-family: sans-serif; font-size: 12px; line-height: 16px; } del { background-color: #FFAB91; color: ; text-decoration: none; } ins { background-color: #C5E1A5; color: ; text-decoration: none; } </style> </head> <body> <div class="container"> <?php echo htmlDiff($old, $new); ?> </div> </body> </head>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/uU0dv
function name:  (null)
number of ops:  10
compiled vars:  !0 = $old, !1 = $new
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   ASSIGN                                                   !0, 'We+smsfactory+are+world%27s+leading+SMS+messaging+provider+offering+remarakable+and+reliable+SMS+Text+and+Voice+messaging+globally+through+almost+all-networks+of+mobile+phones+successfully.+You+may+contact-us+anytime+for+making+any+query.+Our+Services+are+very+useful+economically+as+well+as+eco-friendly'
   42     1        ASSIGN                                                   !1, 'We+smsfactory+are+world%27s+leading+SMS+messaging+provider+offering+remarakable+and+reliable+SMS+Text+and+Voice+messaging+globally+through+almost+all-networks+of+mobile+phones+successfully.+You+may+contact-us+anytime+for+making+any+query.+Our+Services+are+very+useful+economically+as+well+as+eco-friendly%2C+which+enables+you+to+send+simultaneous+bulk+sms+to+your+targeted+Customers%2C+Regular-Customers%2C+Buyers%2C+Shoppers%2C+Fans%2C+Regular-shoppers%2C+Clients%2C+Clientele%2C+Members%2C+Managers%2C+Supervisors%2C+Fieldworkers%2C+Graduates%2C+Post+graduates%2C+Technicians%2C+Public%2C+Citizens%2C+Mobile-Users%2C+Viewers%2C+Future-purchasers%2C+Users%2C+End-users%2C+Students%2C+Job-seekers%2C+Enjoyers%2C+Visitors%2C+Frequent-visitors%2C+Persons%2C+Individuals%2C+Frequenter%2C+Obtainers%2C+Receivers%2C+Assignees%2C+Recipients%2C+Travelers%2C+Tourists%2C+Guys%2C+Persons%2C+Men+and+Women%2C+Spectators%2C+Technicians%2C+Staff%2C+Workers%2C+Recruiters%2C+Newcomers%2C+Representatives%2C+Dealers%2C+Distributors%2C+Followers%2C+Shareholders%2C+Investors%2C+Bondholders%2C+Shareowners%2C+Financiers%2C+Bankers%2C+Participants%2C+Associates%2C+Assistants%2C+Colleagues%2C+Contributors%2C+Helpers%2C+Partakers%2C+Party%2C+Sharers%2C+Supporters%2C+Admirers%2C+Devotees%2C+Groupies%2C+Enthusiasts+and+many+more.'
   45     2        ECHO                                                     '%3C%21doctype+html%3E%0A%3Chead%3E%0A%09%3Cstyle%3E%0A%09%09.container+%7B%0A%09%09%09width%3A+50%25%3B%0A%09%09%09margin-right%3A+auto%3B%0A%09%09%09margin-left%3A+auto%3B%0A%09%09%09font-family%3A+sans-serif%3B%0A%09%09%09font-size%3A+12px%3B%0A%09%09%09line-height%3A+16px%3B%0A%09%09%7D%0A%09%09%0A%09%09del+%7B%0A%09%09%09background-color%3A+%23FFAB91%3B%0A%09%09%09color%3A+%3B%0A%09%09%09text-decoration%3A+none%3B%0A%09%09%7D%0A%09%09%0A%09%09ins+%7B%0A%09%09%09background-color%3A+%23C5E1A5%3B%0A%09%09%09color%3A+%3B%0A%09%09%09text-decoration%3A+none%3B%0A%09%09%7D%0A%09%3C%2Fstyle%3E%0A%3C%2Fhead%3E%0A%3Cbody%3E%0A%09%3Cdiv+class%3D%22container%22%3E%0A%09%09'
   72     3        INIT_FCALL                                               'htmldiff'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        DO_FCALL                                      0  $4      
          7        ECHO                                                     $4
   73     8        ECHO                                                     '%09%3C%2Fdiv%3E%09%0A%3C%2Fbody%3E%0A%3C%2Fhead%3E'
   75     9      > RETURN                                                   1

Function diff:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 46
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 46
Branch analysis from position: 6
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 44
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 44
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 26
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 43
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 43
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 43
Branch analysis from position: 34
Branch analysis from position: 43
Branch analysis from position: 44
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 44
Branch analysis from position: 46
2 jumps found. (Code = 43) Position 1 = 49, Position 2 = 53
Branch analysis from position: 49
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 53
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 46
filename:       /in/uU0dv
function name:  diff
number of ops:  93
compiled vars:  !0 = $old, !1 = $new, !2 = $matrix, !3 = $maxlen, !4 = $ovalue, !5 = $oindex, !6 = $nkeys, !7 = $nindex, !8 = $omax, !9 = $nmax
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    8     2        ASSIGN                                                   !2, <array>
    9     3        ASSIGN                                                   !3, 0
   10     4      > FE_RESET_R                                       $12     !0, ->46
          5    > > FE_FETCH_R                                       ~13     $12, !4, ->46
          6    >   ASSIGN                                                   !5, ~13
   11     7        INIT_FCALL                                               'array_keys'
          8        SEND_VAR                                                 !1
          9        SEND_VAR                                                 !4
         10        DO_ICALL                                         $15     
         11        ASSIGN                                                   !6, $15
   12    12      > FE_RESET_R                                       $17     !6, ->44
         13    > > FE_FETCH_R                                               $17, !7, ->44
   13    14    >   SUB                                              ~20     !5, 1
         15        SUB                                              ~22     !7, 1
         16        FETCH_DIM_IS                                     ~21     !2, ~20
         17        ISSET_ISEMPTY_DIM_OBJ                         0          ~21, ~22
         18      > JMPZ                                                     ~23, ->26
   14    19    >   SUB                                              ~24     !5, 1
         20        SUB                                              ~26     !7, 1
         21        FETCH_DIM_R                                      ~25     !2, ~24
         22        FETCH_DIM_R                                      ~27     ~25, ~26
         23        ADD                                              ~28     ~27, 1
         24        QM_ASSIGN                                        ~29     ~28
         25      > JMP                                                      ->27
         26    >   QM_ASSIGN                                        ~29     1
   13    27    >   FETCH_DIM_W                                      $18     !2, !5
         28        ASSIGN_DIM                                               $18, !7
   14    29        OP_DATA                                                  ~29
   15    30        FETCH_DIM_R                                      ~30     !2, !5
         31        FETCH_DIM_R                                      ~31     ~30, !7
         32        IS_SMALLER                                               !3, ~31
         33      > JMPZ                                                     ~32, ->43
   16    34    >   FETCH_DIM_R                                      ~33     !2, !5
         35        FETCH_DIM_R                                      ~34     ~33, !7
         36        ASSIGN                                                   !3, ~34
   17    37        ADD                                              ~36     !5, 1
         38        SUB                                              ~37     ~36, !3
         39        ASSIGN                                                   !8, ~37
   18    40        ADD                                              ~39     !7, 1
         41        SUB                                              ~40     ~39, !3
         42        ASSIGN                                                   !9, ~40
   12    43    > > JMP                                                      ->13
         44    >   FE_FREE                                                  $17
   10    45      > JMP                                                      ->5
         46    >   FE_FREE                                                  $12
   22    47        IS_EQUAL                                                 !3, 0
         48      > JMPZ                                                     ~42, ->53
         49    >   INIT_ARRAY                                       ~43     !0, 'd'
         50        ADD_ARRAY_ELEMENT                                ~43     !1, 'i'
         51        INIT_ARRAY                                       ~44     ~43
         52      > RETURN                                                   ~44
   23    53    >   INIT_FCALL                                               'array_merge'
   24    54        INIT_FCALL_BY_NAME                                       'diff'
         55        INIT_FCALL                                               'array_slice'
         56        SEND_VAR                                                 !0
         57        SEND_VAL                                                 0
         58        SEND_VAR                                                 !8
         59        DO_ICALL                                         $45     
         60        SEND_VAR_NO_REF_EX                                       $45
         61        INIT_FCALL                                               'array_slice'
         62        SEND_VAR                                                 !1
         63        SEND_VAL                                                 0
         64        SEND_VAR                                                 !9
         65        DO_ICALL                                         $46     
         66        SEND_VAR_NO_REF_EX                                       $46
         67        DO_FCALL                                      0  $47     
         68        SEND_VAR                                                 $47
   25    69        INIT_FCALL                                               'array_slice'
         70        SEND_VAR                                                 !1
         71        SEND_VAR                                                 !9
         72        SEND_VAR                                                 !3
         73        DO_ICALL                                         $48     
         74        SEND_VAR                                                 $48
   26    75        INIT_FCALL_BY_NAME                                       'diff'
         76        INIT_FCALL                                               'array_slice'
         77        SEND_VAR                                                 !0
         78        ADD                                              ~49     !8, !3
         79        SEND_VAL                                                 ~49
         80        DO_ICALL                                         $50     
         81        SEND_VAR_NO_REF_EX                                       $50
         82        INIT_FCALL                                               'array_slice'
         83        SEND_VAR                                                 !1
         84        ADD                                              ~51     !9, !3
         85        SEND_VAL                                                 ~51
         86        DO_ICALL                                         $52     
         87        SEND_VAR_NO_REF_EX                                       $52
         88        DO_FCALL                                      0  $53     
         89        SEND_VAR                                                 $53
   23    90        DO_ICALL                                         $54     
   26    91      > RETURN                                                   $54
   27    92*     > RETURN                                                   null

End of function diff

Function htmldiff:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 17, Position 2 = 52
Branch analysis from position: 17
2 jumps found. (Code = 78) Position 1 = 18, Position 2 = 52
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 49
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 32
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 45
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 51
Branch analysis from position: 51
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 51
Branch analysis from position: 51
Branch analysis from position: 32
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 45
Branch analysis from position: 36
Branch analysis from position: 45
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 52
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 52
filename:       /in/uU0dv
function name:  htmlDiff
number of ops:  55
compiled vars:  !0 = $old, !1 = $new, !2 = $ret, !3 = $diff, !4 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   29     2        ASSIGN                                                   !2, ''
   30     3        INIT_FCALL                                               'diff'
          4        INIT_FCALL                                               'preg_split'
          5        SEND_VAL                                                 '%2F%5B%5Cs%5D%2B%2F'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $6      
          8        SEND_VAR                                                 $6
          9        INIT_FCALL                                               'preg_split'
         10        SEND_VAL                                                 '%2F%5B%5Cs%5D%2B%2F'
         11        SEND_VAR                                                 !1
         12        DO_ICALL                                         $7      
         13        SEND_VAR                                                 $7
         14        DO_FCALL                                      0  $8      
         15        ASSIGN                                                   !3, $8
   31    16      > FE_RESET_R                                       $10     !3, ->52
         17    > > FE_FETCH_R                                               $10, !4, ->52
   32    18    >   TYPE_CHECK                                  128          !4
         19      > JMPZ                                                     ~11, ->49
   33    20    >   ISSET_ISEMPTY_DIM_OBJ                         1  ~12     !4, 'd'
         21        BOOL_NOT                                         ~13     ~12
         22      > JMPZ                                                     ~13, ->32
         23    >   INIT_FCALL                                               'implode'
         24        SEND_VAL                                                 '+'
         25        FETCH_DIM_R                                      ~14     !4, 'd'
         26        SEND_VAL                                                 ~14
         27        DO_ICALL                                         $15     
         28        CONCAT                                           ~16     '%3Cdel%3E', $15
         29        CONCAT                                           ~17     ~16, '%3C%2Fdel%3E+'
         30        QM_ASSIGN                                        ~18     ~17
         31      > JMP                                                      ->33
         32    >   QM_ASSIGN                                        ~18     ''
   34    33    >   ISSET_ISEMPTY_DIM_OBJ                         1  ~19     !4, 'i'
         34        BOOL_NOT                                         ~20     ~19
         35      > JMPZ                                                     ~20, ->45
         36    >   INIT_FCALL                                               'implode'
         37        SEND_VAL                                                 '+'
         38        FETCH_DIM_R                                      ~21     !4, 'i'
         39        SEND_VAL                                                 ~21
         40        DO_ICALL                                         $22     
         41        CONCAT                                           ~23     '%3Cins%3E', $22
         42        CONCAT                                           ~24     ~23, '%3C%2Fins%3E+'
         43        QM_ASSIGN                                        ~25     ~24
         44      > JMP                                                      ->46
         45    >   QM_ASSIGN                                        ~25     ''
         46    >   CONCAT                                           ~26     ~18, ~25
         47        ASSIGN_OP                                     8          !2, ~26
   32    48      > JMP                                                      ->51
   35    49    >   CONCAT                                           ~28     !4, '+'
         50        ASSIGN_OP                                     8          !2, ~28
   31    51    > > JMP                                                      ->17
         52    >   FE_FREE                                                  $10
   37    53      > RETURN                                                   !2
   38    54*     > RETURN                                                   null

End of function htmldiff

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.77 ms | 1023 KiB | 20 Q