3v4l.org

run code in 300+ PHP versions simultaneously
<?php function get_icon( $html, $url ) { // Grab the icon's link element. $pattern = '#<link\s[^>]*rel=(?:[\"\']??)\s*(?:icon|shortcut icon|icon shortcut)\s*(?:[\"\']??)[^>]*\/?>#isU'; preg_match( $pattern, $html, $element ); $element = ! empty( $element[0] ) && is_string( $element[0] ) ? trim( $element[0] ) : ''; if ( empty( $element ) ) { return ''; } // Get the icon's href value. $pattern = '#href=([\"\']??)([^\" >]*?)\\1[^>]*#isU'; preg_match( $pattern, $element, $icon ); $icon = ! empty( $icon[2] ) && is_string( $icon[2] ) ? trim( $icon[2] ) : ''; if ( empty( $icon ) ) { return ''; } // If the icon is a data URL, return it. $parsed_icon = parse_url( $icon ); var_dump( $parsed_icon ); if ( 'data' === $parsed_icon['scheme'] ) { return $icon; } // Attempt to convert relative URLs to absolute. $parsed_url = parse_url( $url ); $root_url = $parsed_url['scheme'] . '://' . $parsed_url['host'] . '/'; $icon = WP_Http::make_absolute_url( $icon, $root_url ); return $icon; } $html = array( '<link href="data:image/png;base64,iVBORw0KGgo=" rel="icon" type="image/png" />', '<link rel="icon" href="data:image/x-icon;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQEAYAAABPYyMiAAAABmJLR0T///////8JWPfcAAAACXBIWXMAAABIAAAASABGyWs+AAAAF0lEQVRIx2NgGAWjYBSMglEwCkbBSAcACBAAAeaR9cIAAAAASUVORK5CYII=" type="image/x-icon" />', ); foreach ( $html as $icon_html ) { $icon = get_icon( $icon_html, '' ); var_dump( $icon ); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 12
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 12
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/aaDc9
function name:  (null)
number of ops:  14
compiled vars:  !0 = $html, !1 = $icon_html, !2 = $icon
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   ASSIGN                                                   !0, <array>
   41     1      > FE_RESET_R                                       $4      !0, ->12
          2    > > FE_FETCH_R                                               $4, !1, ->12
   42     3    >   INIT_FCALL                                               'get_icon'
          4        SEND_VAR                                                 !1
          5        SEND_VAL                                                 ''
          6        DO_FCALL                                      0  $5      
          7        ASSIGN                                                   !2, $5
   43     8        INIT_FCALL                                               'var_dump'
          9        SEND_VAR                                                 !2
         10        DO_ICALL                                                 
   41    11      > JMP                                                      ->2
         12    >   FE_FREE                                                  $4
   44    13      > RETURN                                                   1

Function get_icon:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 11, Position 2 = 14
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 21
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 26
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
2 jumps found. (Code = 46) Position 1 = 35, Position 2 = 38
Branch analysis from position: 35
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 45
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
2 jumps found. (Code = 43) Position 1 = 49, Position 2 = 50
Branch analysis from position: 49
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 50
2 jumps found. (Code = 43) Position 1 = 60, Position 2 = 61
Branch analysis from position: 60
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 61
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 45
2 jumps found. (Code = 43) Position 1 = 49, Position 2 = 50
Branch analysis from position: 49
Branch analysis from position: 50
Branch analysis from position: 38
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 26
Branch analysis from position: 25
Branch analysis from position: 26
Branch analysis from position: 14
filename:       /in/aaDc9
function name:  get_icon
number of ops:  78
compiled vars:  !0 = $html, !1 = $url, !2 = $pattern, !3 = $element, !4 = $icon, !5 = $parsed_icon, !6 = $parsed_url, !7 = $root_url
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2        ASSIGN                                                   !2, '%23%3Clink%5Cs%5B%5E%3E%5D%2Arel%3D%28%3F%3A%5B%5C%22%27%5D%3F%3F%29%5Cs%2A%28%3F%3Aicon%7Cshortcut+icon%7Cicon+shortcut%29%5Cs%2A%28%3F%3A%5B%5C%22%27%5D%3F%3F%29%5B%5E%3E%5D%2A%5C%2F%3F%3E%23isU'
    6     3        INIT_FCALL                                               'preg_match'
          4        SEND_VAR                                                 !2
          5        SEND_VAR                                                 !0
          6        SEND_REF                                                 !3
          7        DO_ICALL                                                 
    7     8        ISSET_ISEMPTY_DIM_OBJ                         1  ~10     !3, 0
          9        BOOL_NOT                                         ~11     ~10
         10      > JMPZ_EX                                          ~11     ~11, ->14
         11    >   FETCH_DIM_R                                      ~12     !3, 0
         12        TYPE_CHECK                                   64  ~13     ~12
         13        BOOL                                             ~11     ~13
         14    > > JMPZ                                                     ~11, ->21
         15    >   INIT_FCALL                                               'trim'
         16        FETCH_DIM_R                                      ~14     !3, 0
         17        SEND_VAL                                                 ~14
         18        DO_ICALL                                         $15     
         19        QM_ASSIGN                                        ~16     $15
         20      > JMP                                                      ->22
         21    >   QM_ASSIGN                                        ~16     ''
         22    >   ASSIGN                                                   !3, ~16
    8    23        ISSET_ISEMPTY_CV                                         !3
         24      > JMPZ                                                     ~18, ->26
    9    25    > > RETURN                                                   ''
   13    26    >   ASSIGN                                                   !2, '%23href%3D%28%5B%5C%22%27%5D%3F%3F%29%28%5B%5E%5C%22+%3E%5D%2A%3F%29%5C1%5B%5E%3E%5D%2A%23isU'
   14    27        INIT_FCALL                                               'preg_match'
         28        SEND_VAR                                                 !2
         29        SEND_VAR                                                 !3
         30        SEND_REF                                                 !4
         31        DO_ICALL                                                 
   15    32        ISSET_ISEMPTY_DIM_OBJ                         1  ~21     !4, 2
         33        BOOL_NOT                                         ~22     ~21
         34      > JMPZ_EX                                          ~22     ~22, ->38
         35    >   FETCH_DIM_R                                      ~23     !4, 2
         36        TYPE_CHECK                                   64  ~24     ~23
         37        BOOL                                             ~22     ~24
         38    > > JMPZ                                                     ~22, ->45
         39    >   INIT_FCALL                                               'trim'
         40        FETCH_DIM_R                                      ~25     !4, 2
         41        SEND_VAL                                                 ~25
         42        DO_ICALL                                         $26     
         43        QM_ASSIGN                                        ~27     $26
         44      > JMP                                                      ->46
         45    >   QM_ASSIGN                                        ~27     ''
         46    >   ASSIGN                                                   !4, ~27
   16    47        ISSET_ISEMPTY_CV                                         !4
         48      > JMPZ                                                     ~29, ->50
   17    49    > > RETURN                                                   ''
   21    50    >   INIT_FCALL                                               'parse_url'
         51        SEND_VAR                                                 !4
         52        DO_ICALL                                         $30     
         53        ASSIGN                                                   !5, $30
   22    54        INIT_FCALL                                               'var_dump'
         55        SEND_VAR                                                 !5
         56        DO_ICALL                                                 
   23    57        FETCH_DIM_R                                      ~33     !5, 'scheme'
         58        IS_IDENTICAL                                             ~33, 'data'
         59      > JMPZ                                                     ~34, ->61
   24    60    > > RETURN                                                   !4
   28    61    >   INIT_FCALL                                               'parse_url'
         62        SEND_VAR                                                 !1
         63        DO_ICALL                                         $35     
         64        ASSIGN                                                   !6, $35
   29    65        FETCH_DIM_R                                      ~37     !6, 'scheme'
         66        CONCAT                                           ~38     ~37, '%3A%2F%2F'
         67        FETCH_DIM_R                                      ~39     !6, 'host'
         68        CONCAT                                           ~40     ~38, ~39
         69        CONCAT                                           ~41     ~40, '%2F'
         70        ASSIGN                                                   !7, ~41
   30    71        INIT_STATIC_METHOD_CALL                                  'WP_Http', 'make_absolute_url'
         72        SEND_VAR_EX                                              !4
         73        SEND_VAR_EX                                              !7
         74        DO_FCALL                                      0  $43     
         75        ASSIGN                                                   !4, $43
   32    76      > RETURN                                                   !4
   33    77*     > RETURN                                                   null

End of function get_icon

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
281.45 ms | 1016 KiB | 18 Q