3v4l.org

run code in 300+ PHP versions simultaneously
<?php function um_youtube_id_from_url($url) { $pattern = '%^# Match any youtube URL (?:https?://)? # Optional scheme. Either http or https (?:www\.)? # Optional www subdomain (?: # Group host alternatives youtu\.be/ # Either youtu.be, | youtube\.com # or youtube.com (?: # Group path alternatives /embed/ # Either /embed/ | /v/ # or /v/ | /watch\?v= # or /watch\?v= ) # End path alternatives. ) # End host alternatives. ([\w-]{10,12}) # Allow 10-12 for 11 char youtube id. $%x' ; $result = preg_match($pattern, $url, $matches); if (false !== $result) { return $matches[1]; } return false; } var_dump(um_youtube_id_from_url('<a href="https://www.youtube.com/watch?v=1aaXl4vaeJU">https://www.youtube.com/watch?v=1aaXl4vaeJU</a>')); var_dump(um_youtube_id_from_url("https://www.youtube.com/watch?v=1aaXl4vaeJU")); var_dump(um_youtube_id_from_url("https://www.youtube.com/v/1aaXl4vaeJU"));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tKOvA
function name:  (null)
number of ops:  19
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'um_youtube_id_from_url'
          2        SEND_VAL                                                 '%3Ca+href%3D%22https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D1aaXl4vaeJU%22%3Ehttps%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D1aaXl4vaeJU%3C%2Fa%3E'
          3        DO_FCALL                                      0  $0      
          4        SEND_VAR                                                 $0
          5        DO_ICALL                                                 
   26     6        INIT_FCALL                                               'var_dump'
          7        INIT_FCALL                                               'um_youtube_id_from_url'
          8        SEND_VAL                                                 'https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D1aaXl4vaeJU'
          9        DO_FCALL                                      0  $2      
         10        SEND_VAR                                                 $2
         11        DO_ICALL                                                 
   27    12        INIT_FCALL                                               'var_dump'
         13        INIT_FCALL                                               'um_youtube_id_from_url'
         14        SEND_VAL                                                 'https%3A%2F%2Fwww.youtube.com%2Fv%2F1aaXl4vaeJU'
         15        DO_FCALL                                      0  $4      
         16        SEND_VAR                                                 $4
         17        DO_ICALL                                                 
         18      > RETURN                                                   1

Function um_youtube_id_from_url:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tKOvA
function name:  um_youtube_id_from_url
number of ops:  14
compiled vars:  !0 = $url, !1 = $pattern, !2 = $result, !3 = $matches
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    3     1        ASSIGN                                                   !1, '%25%5E%23+Match+any+youtube+URL%0A++++++++%28%3F%3Ahttps%3F%3A%2F%2F%29%3F++%23+Optional+scheme.+Either+http+or+https%0A++++++++%28%3F%3Awww%5C.%29%3F++++++%23+Optional+www+subdomain%0A++++++++%28%3F%3A+++++++++++++%23+Group+host+alternatives%0A++++++++++youtu%5C.be%2F++++%23+Either+youtu.be%2C%0A++++++++%7C+youtube%5C.com++%23+or+youtube.com%0A++++++++++%28%3F%3A+++++++++++%23+Group+path+alternatives%0A++++++++++++%2Fembed%2F+++++%23+Either+%2Fembed%2F%0A++++++++++%7C+%2Fv%2F+++++++++%23+or+%2Fv%2F%0A++++++++++%7C+%2Fwatch%5C%3Fv%3D++%23+or+%2Fwatch%5C%3Fv%3D%0A++++++++++%29+++++++++++++%23+End+path+alternatives.%0A++++++++%29+++++++++++++++%23+End+host+alternatives.%0A++++++++%28%5B%5Cw-%5D%7B10%2C12%7D%29++%23+Allow+10-12+for+11+char+youtube+id.%0A++++++++%24%25x'
   19     2        INIT_FCALL                                               'preg_match'
          3        SEND_VAR                                                 !1
          4        SEND_VAR                                                 !0
          5        SEND_REF                                                 !3
          6        DO_ICALL                                         $5      
          7        ASSIGN                                                   !2, $5
   20     8        TYPE_CHECK                                  1018          !2
          9      > JMPZ                                                     ~7, ->12
   21    10    >   FETCH_DIM_R                                      ~8      !3, 1
         11      > RETURN                                                   ~8
   23    12    > > RETURN                                                   <false>
   24    13*     > RETURN                                                   null

End of function um_youtube_id_from_url

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
176.47 ms | 1403 KiB | 20 Q