3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Function `parse_yturl()` from <http://stackoverflow.com/a/10524505/624466> /** * Check if the input string is a valid YouTube URL * and try to extract the YouTube Video ID from it. * * @author Stephan Schmitz <eyecatchup@gmail.com> * @param $url string The string that shall be checked. * @return mixed YouTube Video ID, or (boolean) false. */ function parse_yturl($url) { $pattern = '#^(?:https?://|//)?' # Optional URL scheme. Either http, or https, or protocol-relative. . '(?:www\.|m\.)?' # Optional www or m 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=, . '|watch\?.+&v=' # or /watch?other_param&v= . ')' # End path alternatives. . ')' # End host alternatives. . '([\w-]{11})' # 11 characters (Length of Youtube video ids). . '(?![\w-])#'; # Rejects if overlong id. preg_match($pattern, $url, $matches); return (isset($matches[1])) ? $matches[1] : false; } // Tests for function `parse_yturl()` $testIds = [ 'l8qdouU9cYE', '_PqP1qHhsyM', '3G3_im4RyI8', 'uqU4Mkd-_gU', ]; $testUrls = [ // Without scheme and subdomain (Domain: youtu.be, Path: /) 'youtu.be/%s', // Without scheme, with subdomain (Domain: youtu.be, Path: /) 'www.youtu.be/%s', // With HTTP scheme, without subdomain (Domain: youtu.be, Path: /) 'http://youtu.be/%s', // With HTTP scheme and subdomain (Domain: youtu.be, Path: /) 'http://www.youtu.be/%s', // With HTTPS scheme, without subdomain (Domain: youtu.be, Path: /) 'https://youtu.be/%s', // With HTTPS scheme and subdomain (Domain: youtu.be, Path: /) 'https://www.youtu.be/%s', // Without scheme and subdomain (Domain: youtube.com, Path: /embed) 'youtube.com/embed/%s', 'youtube.com/embed/%s&other_params', // Without scheme, with subdomain (Domain: youtube.com, Path: /embed) 'www.youtube.com/embed/%s', 'www.youtube.com/embed/%s&other_params', // With HTTP scheme, without subdomain (Domain: youtube.com, Path: /embed) 'http://youtube.com/embed/%s', 'http://youtube.com/embed/%s&other_params', // With HTTP scheme and subdomain (Domain: youtube.com, Path: /embed) 'http://www.youtube.com/embed/%s', 'http://www.youtube.com/embed/%s&other_params', // With HTTPS scheme, without subdomain (Domain: youtube.com, Path: /embed) 'https://youtube.com/embed/%s', 'https://youtube.com/embed/%s&other_params', // With HTTPS scheme and subdomain (Domain: youtube.com, Path: /embed) 'https://www.youtube.com/embed/%s', 'https://www.youtube.com/embed/%s&other_params', // Without scheme and subdomain (Domain: youtube.com, Path: /v) 'youtube.com/v/%s', 'youtube.com/v/%s&other_params', // Without scheme, with subdomain (Domain: youtube.com, Path: /v) 'www.youtube.com/v/%s', 'www.youtube.com/v/%s&other_params', // With HTTP scheme, without subdomain (Domain: youtube.com, Path: /v) 'http://youtube.com/v/%s', 'http://youtube.com/v/%s&other_params', // With HTTP scheme and subdomain (Domain: youtube.com, Path: /v) 'http://www.youtube.com/v/%s', 'http://www.youtube.com/v/%s&other_params', // With HTTPS scheme, without subdomain (Domain: youtube.com, Path: /v) 'https://youtube.com/v/%s', 'https://youtube.com/v/%s&other_params', // With HTTPS scheme and subdomain (Domain: youtube.com, Path: /v) 'https://www.youtube.com/v/%s', 'https://www.youtube.com/v/%s&other_params', // Without scheme and subdomain (Domain: youtube.com, Path: /watch) 'youtube.com/watch?v=%s', 'youtube.com/watch?v=%s&other_params', 'youtube.com/watch?other_params&v=%s', 'youtube.com/watch?other_params&v=%s&more_params', // Without scheme, with subdomain (Domain: youtube.com, Path: /watch) 'www.youtube.com/watch?v=%s', 'www.youtube.com/watch?v=%s&other_params', 'www.youtube.com/watch?other_params&v=%s', 'www.youtube.com/watch?other_params&v=%s&more_params', // With HTTP scheme, without subdomain (Domain: youtube.com, Path: /watch) 'http://youtube.com/watch?v=%s', 'http://youtube.com/watch?v=%s&other_params', 'http://youtube.com/watch?other_params&v=%s', 'http://youtube.com/watch?other_params&v=%s&more_params', // With HTTP scheme and subdomain (Domain: youtube.com, Path: /watch) 'http://www.youtube.com/watch?v=%s', 'http://www.youtube.com/watch?v=%s&other_params', 'http://www.youtube.com/watch?other_params&v=%s', 'http://www.youtube.com/watch?other_params&v=%s&more_params', // With HTTPS scheme, without subdomain (Domain: youtube.com, Path: /watch) 'https://youtube.com/watch?v=%s', 'https://youtube.com/watch?v=%s&other_params', 'https://youtube.com/watch?other_params&v=%s', 'https://youtube.com/watch?other_params&v=%s&more_params', // With HTTPS scheme and subdomain (Domain: youtube.com, Path: /watch) 'https://www.youtube.com/watch?v=%s', 'https://www.youtube.com/watch?v=%s&other_params', 'https://www.youtube.com/watch?other_params&v=%s', 'https://www.youtube.com/watch?other_params&v=%s&more_params', ]; $results = []; foreach ($testIds as $id) { $results[$id] = []; foreach ($testUrls as $str) { $testString = sprintf($str, $id); array_push($results[$id], [ 'str' => $testString, 'id' => parse_yturl($testString), ]); } } $matches = 0; $errors = 0; foreach ($results as $key => $val) { $testId = $key; printf('# Testing strings for id "%s"' . PHP_EOL . PHP_EOL, $testId); foreach ($val as $res) { if ($res['id'] !== $testId) { $errors++; $result = 'no match'; } else { $matches++; $result = $res['id']; } printf(' Result: %s, String: %s' . PHP_EOL, $result, $res['str']); } print PHP_EOL; } printf('Done. %d assertation(s), %d error(s)' . PHP_EOL, $matches, $errors);

Abusive script

This script was stopped while abusing our resources

Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 27
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 27
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 25
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 25
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 25
Branch analysis from position: 27
2 jumps found. (Code = 77) Position 1 = 31, Position 2 = 59
Branch analysis from position: 31
2 jumps found. (Code = 78) Position 1 = 32, Position 2 = 59
Branch analysis from position: 32
2 jumps found. (Code = 77) Position 1 = 39, Position 2 = 56
Branch analysis from position: 39
2 jumps found. (Code = 78) Position 1 = 40, Position 2 = 56
Branch analysis from position: 40
2 jumps found. (Code = 43) Position 1 = 43, Position 2 = 46
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
Branch analysis from position: 56
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
Branch analysis from position: 56
Branch analysis from position: 59
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 59
Branch analysis from position: 27
filename:       /in/GEDT0
function name:  (null)
number of ops:  66
compiled vars:  !0 = $testIds, !1 = $testUrls, !2 = $results, !3 = $id, !4 = $str, !5 = $testString, !6 = $matches, !7 = $errors, !8 = $val, !9 = $key, !10 = $testId, !11 = $res, !12 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   ASSIGN                                                   !0, <array>
   41     1        ASSIGN                                                   !1, <array>
  122     2        ASSIGN                                                   !2, <array>
  124     3      > FE_RESET_R                                       $16     !0, ->27
          4    > > FE_FETCH_R                                               $16, !3, ->27
  125     5    >   ASSIGN_DIM                                               !2, !3
          6        OP_DATA                                                  <array>
  127     7      > FE_RESET_R                                       $18     !1, ->25
          8    > > FE_FETCH_R                                               $18, !4, ->25
  128     9    >   INIT_FCALL                                               'sprintf'
         10        SEND_VAR                                                 !4
         11        SEND_VAR                                                 !3
         12        DO_ICALL                                         $19     
         13        ASSIGN                                                   !5, $19
  129    14        INIT_FCALL                                               'array_push'
         15        FETCH_DIM_W                                      $21     !2, !3
         16        SEND_REF                                                 $21
  130    17        INIT_ARRAY                                       ~22     !5, 'str'
  131    18        INIT_FCALL                                               'parse_yturl'
         19        SEND_VAR                                                 !5
         20        DO_FCALL                                      0  $23     
         21        ADD_ARRAY_ELEMENT                                ~22     $23, 'id'
         22        SEND_VAL                                                 ~22
  129    23        DO_ICALL                                                 
  127    24      > JMP                                                      ->8
         25    >   FE_FREE                                                  $18
  124    26      > JMP                                                      ->4
         27    >   FE_FREE                                                  $16
  136    28        ASSIGN                                                   !6, 0
  137    29        ASSIGN                                                   !7, 0
  139    30      > FE_RESET_R                                       $27     !2, ->59
         31    > > FE_FETCH_R                                       ~28     $27, !8, ->59
         32    >   ASSIGN                                                   !9, ~28
  140    33        ASSIGN                                                   !10, !9
  141    34        INIT_FCALL                                               'printf'
         35        SEND_VAL                                                 '%23+Testing+strings+for+id+%22%25s%22%0A%0A'
         36        SEND_VAR                                                 !10
         37        DO_ICALL                                                 
  143    38      > FE_RESET_R                                       $32     !8, ->56
         39    > > FE_FETCH_R                                               $32, !11, ->56
  144    40    >   FETCH_DIM_R                                      ~33     !11, 'id'
         41        IS_NOT_IDENTICAL                                         !10, ~33
         42      > JMPZ                                                     ~34, ->46
  145    43    >   PRE_INC                                                  !7
  146    44        ASSIGN                                                   !12, 'no+match'
  144    45      > JMP                                                      ->49
  148    46    >   PRE_INC                                                  !6
  149    47        FETCH_DIM_R                                      ~38     !11, 'id'
         48        ASSIGN                                                   !12, ~38
  151    49    >   INIT_FCALL                                               'printf'
         50        SEND_VAL                                                 '++Result%3A+%25s%2C+String%3A+%25s%0A'
         51        SEND_VAR                                                 !12
         52        FETCH_DIM_R                                      ~40     !11, 'str'
         53        SEND_VAL                                                 ~40
         54        DO_ICALL                                                 
  143    55      > JMP                                                      ->39
         56    >   FE_FREE                                                  $32
  153    57        ECHO                                                     '%0A'
  139    58      > JMP                                                      ->31
         59    >   FE_FREE                                                  $27
  156    60        INIT_FCALL                                               'printf'
         61        SEND_VAL                                                 'Done.+%25d+assertation%28s%29%2C+%25d+error%28s%29%0A'
         62        SEND_VAR                                                 !6
         63        SEND_VAR                                                 !7
         64        DO_ICALL                                                 
         65      > RETURN                                                   1

Function parse_yturl:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 12
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GEDT0
function name:  parse_yturl
number of ops:  15
compiled vars:  !0 = $url, !1 = $pattern, !2 = $matches
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
   14     1        ASSIGN                                                   !1, '%23%5E%28%3F%3Ahttps%3F%3A%2F%2F%7C%2F%2F%29%3F%28%3F%3Awww%5C.%7Cm%5C.%29%3F%28%3F%3Ayoutu%5C.be%2F%7Cyoutube%5C.com%2F%28%3F%3Aembed%2F%7Cv%2F%7Cwatch%5C%3Fv%3D%7Cwatch%5C%3F.%2B%26v%3D%29%29%28%5B%5Cw-%5D%7B11%7D%29%28%3F%21%5B%5Cw-%5D%29%23'
   28     2        INIT_FCALL                                               'preg_match'
          3        SEND_VAR                                                 !1
          4        SEND_VAR                                                 !0
          5        SEND_REF                                                 !2
          6        DO_ICALL                                                 
   29     7        ISSET_ISEMPTY_DIM_OBJ                         0          !2, 1
          8      > JMPZ                                                     ~5, ->12
          9    >   FETCH_DIM_R                                      ~6      !2, 1
         10        QM_ASSIGN                                        ~7      ~6
         11      > JMP                                                      ->13
         12    >   QM_ASSIGN                                        ~7      <false>
         13    > > RETURN                                                   ~7
   30    14*     > RETURN                                                   null

End of function parse_yturl

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.34 ms | 1468 KiB | 18 Q