3v4l.org

run code in 300+ PHP versions simultaneously
<?php function validate_EAN13Barcode($barcode) { // check to see if barcode is 13 digits long if (!preg_match("/^[0-9]{13}$/", $barcode)) { return false; } $digits = $barcode; // 1. Add the values of the digits in the // even-numbered positions: 2, 4, 6, etc. $even_sum = $digits[1] + $digits[3] + $digits[5] + $digits[7] + $digits[9] + $digits[11]; // 2. Multiply this result by 3. $even_sum_three = $even_sum * 3; // 3. Add the values of the digits in the // odd-numbered positions: 1, 3, 5, etc. $odd_sum = $digits[0] + $digits[2] + $digits[4] + $digits[6] + $digits[8] + $digits[10]; // 4. Sum the results of steps 2 and 3. $total_sum = $even_sum_three + $odd_sum; // 5. The check character is the smallest number which, // when added to the result in step 4, produces a multiple of 10. $next_ten = (ceil($total_sum / 10)) * 10; $check_digit = $next_ten - $total_sum; // if the check digit and the last digit of the // barcode are OK return true; if ($check_digit == $digits[12]) { return true; } return false; } echo "ean valide : ".validate_EAN13Barcode(3001209537341)."";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eVRLA
function name:  (null)
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   INIT_FCALL                                               'validate_ean13barcode'
          1        SEND_VAL                                                 3001209537341
          2        DO_FCALL                                      0  $0      
          3        CONCAT                                           ~1      'ean+valide+%3A+', $0
          4        CONCAT                                           ~2      ~1, ''
          5        ECHO                                                     ~2
          6      > RETURN                                                   1

Function validate_ean13barcode:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 8
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
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 = 62) Position 1 = -2
filename:       /in/eVRLA
function name:  validate_EAN13Barcode
number of ops:  51
compiled vars:  !0 = $barcode, !1 = $digits, !2 = $even_sum, !3 = $even_sum_three, !4 = $odd_sum, !5 = $total_sum, !6 = $next_ten, !7 = $check_digit
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    6     1        INIT_FCALL                                               'preg_match'
          2        SEND_VAL                                                 '%2F%5E%5B0-9%5D%7B13%7D%24%2F'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $8      
          5        BOOL_NOT                                         ~9      $8
          6      > JMPZ                                                     ~9, ->8
    7     7    > > RETURN                                                   <false>
   10     8    >   ASSIGN                                                   !1, !0
   14     9        FETCH_DIM_R                                      ~11     !1, 1
         10        FETCH_DIM_R                                      ~12     !1, 3
         11        ADD                                              ~13     ~11, ~12
         12        FETCH_DIM_R                                      ~14     !1, 5
         13        ADD                                              ~15     ~13, ~14
   15    14        FETCH_DIM_R                                      ~16     !1, 7
         15        ADD                                              ~17     ~15, ~16
         16        FETCH_DIM_R                                      ~18     !1, 9
         17        ADD                                              ~19     ~17, ~18
         18        FETCH_DIM_R                                      ~20     !1, 11
         19        ADD                                              ~21     ~19, ~20
   14    20        ASSIGN                                                   !2, ~21
   18    21        MUL                                              ~23     !2, 3
         22        ASSIGN                                                   !3, ~23
   22    23        FETCH_DIM_R                                      ~25     !1, 0
         24        FETCH_DIM_R                                      ~26     !1, 2
         25        ADD                                              ~27     ~25, ~26
         26        FETCH_DIM_R                                      ~28     !1, 4
         27        ADD                                              ~29     ~27, ~28
   23    28        FETCH_DIM_R                                      ~30     !1, 6
         29        ADD                                              ~31     ~29, ~30
         30        FETCH_DIM_R                                      ~32     !1, 8
         31        ADD                                              ~33     ~31, ~32
         32        FETCH_DIM_R                                      ~34     !1, 10
         33        ADD                                              ~35     ~33, ~34
   22    34        ASSIGN                                                   !4, ~35
   26    35        ADD                                              ~37     !3, !4
         36        ASSIGN                                                   !5, ~37
   30    37        INIT_FCALL                                               'ceil'
         38        DIV                                              ~39     !5, 10
         39        SEND_VAL                                                 ~39
         40        DO_ICALL                                         $40     
         41        MUL                                              ~41     $40, 10
         42        ASSIGN                                                   !6, ~41
   31    43        SUB                                              ~43     !6, !5
         44        ASSIGN                                                   !7, ~43
   35    45        FETCH_DIM_R                                      ~45     !1, 12
         46        IS_EQUAL                                                 !7, ~45
         47      > JMPZ                                                     ~46, ->49
   36    48    > > RETURN                                                   <true>
   39    49    > > RETURN                                                   <false>
   40    50*     > RETURN                                                   null

End of function validate_ean13barcode

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.13 ms | 1403 KiB | 18 Q