3v4l.org

run code in 300+ PHP versions simultaneously
<?php function dataFromUrl($url) { $url = trim($url); if (!preg_match('@^data:[^,;]*+(?>\s*+;\s*+[^=,;]++\s*+=\s*+[^,;]*+\s*+)*+\s*+(?<type>;\s*+base64\s*+,\s*+|,)(?<data>.*)$@ADis', $url, $m)) { throw new \Exception('Bar data URL.'); } $data = rawurldecode($m['data']); if (($m['type'] ?? '') !== ',') $data = base64_decode($data); return $data; } var_dump(dataFromUrl('data:text/plain;charset=utf-8;base64,SGVsbG8gd29ybGQh')) . PHP_EOL; var_dump(dataFromUrl('data:text/plain ; charset = utf-8 ; base64, SGVsbG8gd29ybGQh')) . PHP_EOL; var_dump(dataFromUrl('data:; charset = utf-8 ; base64, SGVsbG8gd29ybGQh')) . PHP_EOL; var_dump(dataFromUrl('data:;base64 , SGVsbG8gd29ybGQh')) . PHP_EOL; var_dump(dataFromUrl('data:;base64 , SGVsbG8gd29ybGQh')) . PHP_EOL; var_dump(dataFromUrl('data:text/plain;charset=utf-8,Hello%20world%21')) . PHP_EOL;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tou79
function name:  (null)
number of ops:  49
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'datafromurl'
          2        SEND_VAL                                                 'data%3Atext%2Fplain%3Bcharset%3Dutf-8%3Bbase64%2CSGVsbG8gd29ybGQh'
          3        DO_FCALL                                      0  $0      
          4        SEND_VAR                                                 $0
          5        DO_ICALL                                         $1      
          6        CONCAT                                           ~2      $1, '%0A'
          7        FREE                                                     ~2
   14     8        INIT_FCALL                                               'var_dump'
          9        INIT_FCALL                                               'datafromurl'
         10        SEND_VAL                                                 'data%3Atext%2Fplain++%3B++charset++%3D++utf-8+++%3B++base64%2C++++SGVsbG8gd29ybGQh'
         11        DO_FCALL                                      0  $3      
         12        SEND_VAR                                                 $3
         13        DO_ICALL                                         $4      
         14        CONCAT                                           ~5      $4, '%0A'
         15        FREE                                                     ~5
   15    16        INIT_FCALL                                               'var_dump'
         17        INIT_FCALL                                               'datafromurl'
         18        SEND_VAL                                                 'data%3A%3B++charset++%3D++utf-8+++%3B++base64%2C++++SGVsbG8gd29ybGQh'
         19        DO_FCALL                                      0  $6      
         20        SEND_VAR                                                 $6
         21        DO_ICALL                                         $7      
         22        CONCAT                                           ~8      $7, '%0A'
         23        FREE                                                     ~8
   16    24        INIT_FCALL                                               'var_dump'
         25        INIT_FCALL                                               'datafromurl'
         26        SEND_VAL                                                 'data%3A%3Bbase64++%2C++++SGVsbG8gd29ybGQh'
         27        DO_FCALL                                      0  $9      
         28        SEND_VAR                                                 $9
         29        DO_ICALL                                         $10     
         30        CONCAT                                           ~11     $10, '%0A'
         31        FREE                                                     ~11
   17    32        INIT_FCALL                                               'var_dump'
         33        INIT_FCALL                                               'datafromurl'
         34        SEND_VAL                                                 'data%3A%3Bbase64++%2C++++SGVsbG8gd29ybGQh'
         35        DO_FCALL                                      0  $12     
         36        SEND_VAR                                                 $12
         37        DO_ICALL                                         $13     
         38        CONCAT                                           ~14     $13, '%0A'
         39        FREE                                                     ~14
   18    40        INIT_FCALL                                               'var_dump'
         41        INIT_FCALL                                               'datafromurl'
         42        SEND_VAL                                                 'data%3Atext%2Fplain%3Bcharset%3Dutf-8%2CHello%2520world%2521'
         43        DO_FCALL                                      0  $15     
         44        SEND_VAR                                                 $15
         45        DO_ICALL                                         $16     
         46        CONCAT                                           ~17     $16, '%0A'
         47        FREE                                                     ~17
         48      > RETURN                                                   1

Function datafromurl:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 16
Branch analysis from position: 12
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 30
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
filename:       /in/tou79
function name:  dataFromUrl
number of ops:  32
compiled vars:  !0 = $url, !1 = $m, !2 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        INIT_FCALL                                               'trim'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $3      
          4        ASSIGN                                                   !0, $3
    5     5        INIT_FCALL                                               'preg_match'
          6        SEND_VAL                                                 '%40%5Edata%3A%5B%5E%2C%3B%5D%2A%2B%28%3F%3E%5Cs%2A%2B%3B%5Cs%2A%2B%5B%5E%3D%2C%3B%5D%2B%2B%5Cs%2A%2B%3D%5Cs%2A%2B%5B%5E%2C%3B%5D%2A%2B%5Cs%2A%2B%29%2A%2B%5Cs%2A%2B%28%3F%3Ctype%3E%3B%5Cs%2A%2Bbase64%5Cs%2A%2B%2C%5Cs%2A%2B%7C%2C%29%28%3F%3Cdata%3E.%2A%29%24%40ADis'
          7        SEND_VAR                                                 !0
          8        SEND_REF                                                 !1
          9        DO_ICALL                                         $5      
         10        BOOL_NOT                                         ~6      $5
         11      > JMPZ                                                     ~6, ->16
    6    12    >   NEW                                              $7      'Exception'
         13        SEND_VAL_EX                                              'Bar+data+URL.'
         14        DO_FCALL                                      0          
         15      > THROW                                         0          $7
    8    16    >   INIT_FCALL                                               'rawurldecode'
         17        FETCH_DIM_R                                      ~9      !1, 'data'
         18        SEND_VAL                                                 ~9
         19        DO_ICALL                                         $10     
         20        ASSIGN                                                   !2, $10
    9    21        FETCH_DIM_IS                                     ~12     !1, 'type'
         22        COALESCE                                         ~13     ~12
         23        QM_ASSIGN                                        ~13     ''
         24        IS_NOT_IDENTICAL                                         ~13, '%2C'
         25      > JMPZ                                                     ~14, ->30
         26    >   INIT_FCALL                                               'base64_decode'
         27        SEND_VAR                                                 !2
         28        DO_ICALL                                         $15     
         29        ASSIGN                                                   !2, $15
   10    30    > > RETURN                                                   !2
   11    31*     > RETURN                                                   null

End of function datafromurl

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
179.88 ms | 1398 KiB | 29 Q